新しい angularjs 2.0 で http リクエストを作成する方法と、このサービスをコントローラーにフックする方法を知りたいだけです。
ありがとうございました。
新しい angularjs 2.0 で http リクエストを作成する方法と、このサービスをコントローラーにフックする方法を知りたいだけです。
ありがとうございました。
現在のところ、http モジュール/コンポーネントはまだ開発中であり、まだリリースされていません。当面は、次の 2 つの方法を使用できます。
新しい http サービスの詳細については、こちらをご覧ください。
基本的なサポートはすでに追加されていると思います。この例に基づいて:
'angular2/http' //index.ts から httpInjectables を使用してアプリをブートストラップします。
コンストラクターに Http を注入する constructor(http:Http) //http_comp.ts
http.get('./people.json').map(res => res.json()).subscribe(people => this.people = people);
ここに抜粋があります:
import {Component, View} from 'angular2/core';
import {Http, HTTP_BINDINGS} from 'angular2/http';
import {bootstrap} 'angular2/platform/browser';
import {CORE_DIRECTIVES,NgFor} from 'angular/common';
@Component({
selector: 'app'
})
@View({
templateUrl: 'devices.html',
directives: [CORE_DIRECTIVES,NgFor]
})
export class App {
devices: any;
constructor(http: Http) {
this.devices = [];
http.get('./devices.json').toRx().subscribe(res => this.devices = res.json());
}
}
bootstrap(App,[HTTP_BINDINGS]);
これは、便利な angular2 http 機能を示すレポです。