如何在ES5代碼中使用Angular2提供的HTTP服務? Here是TypeScript示例。在ES5代碼中使用Angular2 HTTP服務
我基本上需要GET和POST請求的例子。
示例here不起作用。 get
似乎是未定義的。
這裏是行不通的例子:
var SearchResultComponent = ng.core.Component({
selector: "search-result",
viewProviders: [ng.http.HTTP_PROVIDERS],
templateUrl: "componentTemplates/SearchResult.html"
}).Class({
constructor: [ng.http.HTTP_PROVIDERS, function(http) {
this.params = params;
this.http = http;
}],
ngOnInit: function(){
console.log(this.http.get); //undefined
}
})
您可以通過添加演示您所嘗試的代碼和確切的錯誤消息的代碼來使其成爲一個有效的問題。證明這個問題的Plunker也不會傷害。 –
完成。編輯帖子並添加了一個例子。 –