-1
我已經在角2應用以下文件:Angular2 HTTP POST拋出訂戶異常
注射服務
@Injectable()
export class CompanyService{
constructor(private http:Http){}
public test():any{
return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah')
.map(res => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
}
元器件
@Component({
templateUrl: 'company.html',
providers: [CompanyService]
})
export class CompanyPage{
constructor(private companyServ:CompanyService){}
//This method is used from a submit for using ngSubmit
public onSubmit():void{
this.companyServ.test().subscribe(data => {
console.log('Data', data);
}, err => {
console.error('Error', err);
}, console.log('End'));
}
}
當視圖被呈現和方法onSubmit
被調用,我得到以下錯誤:
有關錯誤的任何信息,將不勝感激。