我試圖在角2中創建一個自定義服務,但我似乎無法找到有關es5中角2服務的任何文檔(這就是我寫代碼的地方)我試過了使用這種在es5中創建角2服務
(function(app){
app.database=ng.core.Injectable().Class({
constructor:[function(){
this.value="hello world";
}],
get:function(){return this.value},
});
ng.core.Injector.resolveAndCreate([app.database]);
ng.core.provide(app.database,{useClass:app.database});
})(window.app||(window.app={}));
然而,當我把它注射到我的組件,它拋出的錯誤no provider for class0 (class10 -> class0)
我似乎無法弄清楚如何創建自定義的服務。有誰知道如何在es5中做到這一點?
看到http://stackoverflow.com/questions/34532138/how-to-inject -custom-service-to-angular-component-in-plain-es5-javascript –
我無法找到該問題感謝您的參考是否有anisituation你會使用Injector.resoveAndCreate或ng.core.provide? – Binvention
我從來沒有見過'ng.core.Injectable'或'ng.core.Injector'記錄 - 但我是一個angular2 noob:p –