Typescript Angular 2-手动实例化(Http)服务

Typescript Angular 2-手动实例化(Http)服务,typescript,angular,angular2-http,Typescript,Angular,Angular2 Http,是否可以手动实例化Http服务而不将其作为构造函数参数 export class SimpleGridServer { private http: Http; constructor(public options: SimpleServerData) { http = new Http(.../* Argument here */); } } 来实例化这个类 var grid = new SimpleGridServer({/* options */})

是否可以手动实例化Http服务而不将其作为构造函数参数

export class SimpleGridServer {
    private http: Http;
    constructor(public options: SimpleServerData) {
        http = new Http(.../* Argument here */);
    }
}
来实例化这个类

var grid = new SimpleGridServer({/* options */});
我想实例化这个类,而不必依赖于导入SimpleGridServer的组件的Http服务。 如果这是可能的,这种情况的缺点是什么

如果这是可能的,这种情况的缺点是什么

您需要处于Angular DI工作流中才能使用Angular stuff

您可以直接获得angular喷油器的手柄:

import {ReflectiveInjector} from '@angular/core';
import {HTTP_PROVIDERS, Http, Headers} from "@angular/http";
const injector = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]);
const http = injector.get(Http);

您可以使用angular 2 DI,而无需构造函数检查此项