Error using Http JSON AngularJS 2

前端 未结 2 529
半阙折子戏
半阙折子戏 2021-01-20 06:20

I\'m trying to use the following code after trying several ways online tutorials I can not make it work.

..//
import {Http, HTTP_PROVIDERS} from \'angular2/h         


        
2条回答
  •  一生所求
    2021-01-20 06:33

    Well, as the error message states this.http is not a function, it's an object which has several methods. You need this.http.get() method:

    this.http.get('resources/users.json')
        .map(res => res.json())
        .subscribe(users => this.users = users);
    

提交回复
热议问题