How to $emit events from Angular 1.4 new router components to parent controller?

449 views Asked by At

In new angular components, $scope cannot be injected so I can't use the standard $emit.

How to I emit a value from a component to parent controller?

I have this in appCtrl:

 $scope.$on('eventName', function (event, args) {
   this.pageTitle = args.pageTitle;
  }.bind(this));

Usually I have done it using:

this.scope.$emit('eventName', { pageTitle: _this.campaign.title });
1

There are 1 answers

0
Benjamin Hofstetter On

I have a similar issue. I need to do a $scope.apply() in a component.

Check this issue here How can we watch expressions inside a controller in angular 1.4 using angular-new-router

I am not sure if using / injecting $scope into a component is the way to go because of the migraiton path to Angular 2. Maybe there is a better way using zone.js https://github.com/angular/zone.js/