0

How to correctly Invoke this function within listener (which 'this' reference to window scope)?

this.openPackage = function (package) {
...
}

$rootScope.$on('open_Package', function (event, package) {
           openPackage(package); // doesn't work
});
Tom Cohen
  • 143
  • 1
  • 4
  • 11

1 Answers1

0

Just use an arrow func to stay in context:

 $rootScope.$on('open_Package',  (event, package) => {
       this.openPackage(package); // does work
 });
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151