【发布时间】:2016-02-16 17:15:15
【问题描述】:
我在我的 Angular 应用程序中获得了 EXCEPTION: No provider for Http!。我做错了什么?
import {Http, Headers} from 'angular2/http';
import {Injectable} from 'angular2/core'
@Component({
selector: 'greetings-ac-app2',
providers: [],
templateUrl: 'app/greetings-ac2.html',
directives: [NgFor, NgModel, NgIf, FORM_DIRECTIVES],
pipes: []
})
export class GreetingsAcApp2 {
private str:any;
constructor(http: Http) {
this.str = {str:'test'};
http.post('http://localhost:18937/account/registeruiduser/',
JSON.stringify(this.str),
{
headers: new Headers({
'Content-Type': 'application/json'
})
});
【问题讨论】:
-
你不见了
HTTP_PROVIDERS。 -
import/export... 请问各位,这是什么语法?
-
是打字稿语法
-
导入/导出 - 这是 JavaScript 语法 (ES6)
-
如果其中一个答案能够真正解释为什么我们需要导入
HttpModule,以及它的作用,那就太好了。
标签: angular