I am in the middle of the transition code from Angular 1.3 to Angular 1.5 to ES6 components and controllers. I tried to find something here on SO, but not useful enough. Suggestions for how to watch events in scope other than the methods mentioned below. Or how to trigger scope events from a directive. Also, please suggest the correct way to do this, if there is an alternative.
Angular 1.3
angular .module('test') .directive('test', function() { return { link: function(scope) { scope.$on('$stateChangeStart', function(event, toState, toParams) {
Angular 1.5 / ES6
class TestController { constructor($scope) { this._$scope = $scope; } $onInit() { this._$scope.$on('$stateChangeStart', (event, toState, toParams) => {
Edit:
Of interest is the alternative to $ on, not $ watch here, because $ onChange can replace $ watch when you just watch variables. I want to listen to sphere events, since not 100% of Angular 1.3 code can be ported to 1.5, I still have directives that trigger events in scope!
source share