How to use/import http module?

前端 未结 13 2284
鱼传尺愫
鱼传尺愫 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:33

    Much the same in Alpha 42, but it can be noted that Headers and HTTP_PROVIDERS also come from angular2/http.

    import {Http, Headers, HTTP_PROVIDERS} from 'angular2/http';
    
    export class App {
    
      constructor(public http: Http) { }
    
      getThing() {
        this.http.get('http://example.com')
          .map(res => res.text())
          .subscribe(
            data => this.thing = data,
            err => this.logError(err),
            () => console.log('Complete')
          );
      }
    
    }
    

    More on this and how to use observables that get returned over here: https://auth0.com/blog/2015/10/15/angular-2-series-part-3-using-http/

    :)

提交回复
热议问题