2

新しい angularjs 2.0 で http リクエストを作成する方法と、このサービスをコントローラーにフックする方法を知りたいだけです。

ありがとうございました。

4

3 に答える 3

6

現在のところ、http モジュール/コンポーネントはまだ開発中であり、まだリリースされていません。当面は、次の 2 つの方法を使用できます。

新しい http サービスの詳細については、こちらをご覧ください。

于 2015-05-18T18:14:12.127 に答える
5

基本的なサポートはすでに追加されていると思います。このに基づいて:

  1. 'angular2/http' //index.ts から httpInjectables を使用してアプリをブートストラップします。

  2. コンストラクターに Http を注入する constructor(http:Http) //http_comp.ts

  3. http.get('./people.json').map(res => res.json()).subscribe(people => this.people = people);

于 2015-06-17T10:24:50.800 に答える
1

ここに抜粋があります:

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 機能を示すレポです。

https://github.com/kaalpurush/ng2-http

于 2015-09-12T18:42:45.087 に答える