Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to use ng-decorator module
import {Factory, Directive, Provider, Service, Controller} from 'ng-decorators'
@Factory(['$window']) //or Directive or Provider or Service or Controller
class FooBar{
constructor(win){ //if you need to access the injected object it will be passed into the constructor
console.log(win.location.host)
}
logOrigin(){
console.log(this.$window.origin); //all the injected values will be auto injected to the class under this.<injected object>
}
}
app.factory('FooBarService', FooBar);
// or app.directive('FooBarService', FooBar);
// or app.service('FooBarService', FooBar);
// you see my point....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment