angular2从构造函数中注入(Http)

时间:2017-01-14 15:54:49

标签: angular inject

请参阅以下代码

import { Http,HttpModule} from '@angular/http';
import { Injectable,Inject } from '@angular/core';
import 'rxjs/add/operator/toPromise';
export class FINAL
{
    static configs:{};
    @Inject(Http) http:Http;
    constructor()
    {
        if(FINAL.configs === undefined)
        {
            console.log('get configs ...');
            this.http.get('../config.json').toPromise().then(response => {
                FINAL.configs = response;
                return true;
            })
        }
    }
}

this.http未定,为什么?如果我使用constructor( @Inject(Http) http:Http;):我如何通过显式FINAL来获取new xx()类的实例?

0 个答案:

没有答案