Is there a way one can access the directive's object inside its link
function? I am porting code to ES6. And this one is failing for me when I
try to access the directive object inside its link function.
class myDirective {
constructor($parse) {
//DDO properties
this.restrict = "A";
this.scope = {};
this.controllerAs = "SomeCtrl";
this.controller = "SomeCtrl";
this.bindToController = true;
this.$parse = $parse;
}
link(scope, element, attrs) {
console.log(this); //<== the link function is not called in context of
myDirective object and logs "window" instead of myDirective
// Do something with $parse
// This is not working as this.$parse is not available on window obv
let foo = this.$parse("baz");
}
// Create an instance so that we can access this inside link
static directiveFactory($parse) {
myDirective.instance = new myDirective($parse);
return myDirective.instance;
}}
// Inject dependencies
myDirective.directiveFactory.$inject = ["$parse"];
export default myDirective.directiveFactory;
I try to avoid private variables that sit outside of the class and hope
there is a better way to get hold of the directive object.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.