我想在嘗試幾種方法在線教程後使用下面的代碼,我不能使它工作。錯誤使用Http JSON AngularJS 2
..//
import {Http, HTTP_PROVIDERS} from 'angular2/http';
@Component({
viewProviders: [HTTP_PROVIDERS],
template: `
..//
<div class="col-md-6 col-md-offset-3 well">
<input type="button" class="btn btn-success btn-block"
(click)="get()" value="Fetch Users">
<hr>
<ul>
<li *ngFor="#user of users">
Id: {{ user.name }} | Name: {{ user.name }} | JSON: {{ user | json }}
</li>
</ul>
</div>
..//
export class Mov {
//Inicio test http
users: Array<Object>;
http: any;
//
//constructor(@Inject(HttpFactory) http) {
//constructor(http: Http) {
constructor(http: Http){
//
this.http = http;
}
get(){
this.http('resources/users.json')
.map(res => res.json())
.subscribe(users => this.users = users);
}
獲得此錯誤:
EXCEPTION: Error during evaluation of "click"
ORIGINAL EXCEPTION: TypeError: this.http is not a function
誰能告訴我我做錯了,我爲我的英語很抱歉。
這解決了這個問題,謝謝,但我認爲也應答@PankajParkar –
我不知道接受什麼,我認爲兩人幫助解決了這個錯誤。 –
我試了,因爲代碼沒有改變,發佈和答案是解決方案 –