Angular2 Http

1 import http and Inject

import {httpInjectables, Http} from 'angular2/http';
import {Inject} from 'angular2/di';

  

2 init your Http and use it

class App {
    http:Http;
    status:int;

    constructor(@Inject(Http) http) {
        this.http = http;

        this.http.get('test.json').toRx().subscribe((res:Response) => {
            this.status = res.status;
        });
    }
}

3 show the result in the UI

{{status}}

  

posted @ 2015-07-23 21:55  菠萝君  阅读(570)  评论(1编辑  收藏  举报