I’m facing a problem with metadata_resolver.js
metadata_resolver.js:499Uncaught Error: Can't resolve all parameters for HttpService: (Http, String, String, ?)
I have this generic provider that receives as parameter a Class, so in run time it could create an object or call a static method of this class.
Both providers are in providers array in app.module.ts
@Injectable()
export class ClassAService extends HttpService<ClassA> {
constructor(http: Http) {
super(http, 'baseUrl', "endpoint", ClassA);
}
@Injectable()
export class HttpService<T> {
private _collection$: Subject<T[]>;
private _baseUrl: string;
private _dataStore: {
collection: any[]
};
private _constructor: any;
private _endpoint: String;
constructor(public http: Http, private baseUrl: string, endpoint: string, constructor: { new (): T; }) {
...
}
loadAll(): void {
this.http.get(`${this._baseUrl}/${this._endpoint}`)
.map(response => response.json())
.subscribe(
data => {
this._dataStore.collection = <T[]>this._constructor.fromJSONArray(this._constructor, data);
this._collection$.next(this._dataStore.collection);
},
error => console.log(error),
() => console.log('done')
);
}
}
}
myComponent.ts
import { ClassAService } from '../../providers/classA-service';
import { ClassA } from '../../models/classA';
export class MyComponent {
list_a: ClassA[];
constructor(public _dataservice: ClassAService, public viewCtrl: ViewController) {
this._dataservice.collection$.subscribe(
collections => { this.list_a = collections; console.log(this.list_a); });
this._dataservice.loadAll();
}
}