Error using Http JSON AngularJS 2

前端 未结 2 527
半阙折子戏
半阙折子戏 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:31

    Seems like somehow Http isn't get injected correctly. Use @Inject to inject Http dependency.

    import { Component, Inject} from 'angular2/core';
    //above code should be at start.
    
    constructor(@Inject(Http) http: Http) {
    

    @Inject is needed for acquiring dependency when not using Typescript for transpilation of JS.

提交回复
热议问题