2
是否有可能手動實例化Http服務而無需將其作爲構造函數參數進行放置?Angular 2 - 實例化(Http)服務手動
export class SimpleGridServer {
private http: Http;
constructor(public options: SimpleServerData) {
http = new Http(.../* Argument here */);
}
}
要實例化這個類。
var grid = new SimpleGridServer({/* options */});
我想實例化這個類,而不必爲我component
那些進口SimpleGridServer
上HTTP服務的依賴。 如果可能,這種情況有什麼缺點?
我想這是怎麼角2點的工作方式。 – janmvtrinidad
您可以使用角度2 DI而無需構造函數檢查http://stackoverflow.com/a/37812906/1401751 –