首页 > $scope.$on在ES6中的写法

$scope.$on在ES6中的写法

ionic中都是直接写$scope.$on和$scope.$broadcast方法。现在ES6中推荐用this,不会写了。上代码:

class TagsCtrl {
    // @ngInject
    constructor($scope) {
        _.assign(this, {$scope});
    }

    
}

export default TagsCtrl;

如果想在上边这段代码中加个$on的监听事件,要如何写,如何触发?如果把$on的监听事件写在constructor中,外部并不能触发,求解!!!


class TagsCtrl {
   constructor($scope, $http...) {
       this.scope = $scope;
       this.http = $http;
       ...
       
       
       this.scope.$on(func...)
       this.scope.$broadcast(func...)
   }
}

参考文档:链接描述

【热门文章】
【热门文章】