Im trying to create a custom service in angular 2 but i can't seem to find any documentation on angular 2 services in es5 (which is what im writing my code in) i've tried using this
(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={}));
however when i inject it into my component it throws the error no provider for class0 (class10 -> class0)
i can't seem to figure out how to create the custom service. does anyone know how to do this in es5?
Here is a complete sample of dependency injection with ES5. (service into component, service into service). Don't forget to specify your service when bootstrapping your application or within the
providers
attribute of components.In your case, I think that your forgot to add
app.database
in providers. Something like:You could also have a look at this question: