調用Ajax調用我有這個組件:爲什麼我無法從Angular2
import {Component} from 'angular2/core';
import {UserServices} from '../services/UserServices';
@Component({
selector: 'users',
template: '<h1>HOLA</h1>'
})
export class UsersComponent {
users: Object;
constructor(userServices: UserServices) {
userServices.getUsersList();
}
}
,並在UserServices我有這樣的代碼:
import {Http} from 'angular2/http'
export class UserServices {
users: Array<any>;
http: any;
constructor(http: Http) {
this.http = http;
}
getUsersList() {
this.http.get('./users.json').map((res: Response) => res.json()).subscribe(res => console.log(res));
}
}
我要調用一個Ajax調用的users
定製標籤。 但我發現了這個錯誤:
Cannot resolve all parameters for UserServices(?). Make sure they all have valid type or annotations.
當我刪除HTTP參數,進口和調用,它沒有任何錯誤,所以我想這個問題是存在的,但我不能找出問題
完美!非常感謝! – Pablo
@Pablo歡迎您。 :) – PSL
@PSL我有一個問題不涉及這個問題,如果你不介意。 「你多次使用'''''''我的意思是你爲什麼使用'Array'而不是'IUser []'?它是如何調用的,以及我可以在哪裏瞭解更多信息? –
Eggy