How to use/import http module?

前端 未结 13 2318
鱼传尺愫
鱼传尺愫 2020-11-27 16:40

I\'ve been playing with Angular 2 Quickstart.

How can I use/import http module in Angular 2?

I\'ve looked at Angular 2 Todo\'s.js, but it doesn\'t use the ht

13条回答
  •  生来不讨喜
    2020-11-27 17:22

    A simple example using the http module:

    import {Component, View, bootstrap, bind, NgFor} from 'angular2/angular2';
    import {Http, HTTP_BINDINGS} from 'angular2/http'
    
    @Component({
       selector: 'app'
    })
    
    @View({
        templateUrl: 'devices.html',
        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]);
    

提交回复
热议问题