AngularJS and typescript broadcast

半腔热情 提交于 2019-12-13 07:30:02

问题


I have following problem. I want to broadcast array of albums to another controller. Structure of my controllers : Parent - multimediaController, child - multimediaAlbumController. I am sending variable, but i cannot receive i, don't know why actually..

multimediaController.ts

export class MultimediaController {
   $scope;
   static $inject = ['$scope'];
   constructor($scope){
     this.$scope = $scope;
   }
   changeAlbum(){
       this.$scope.$broadcast('prod', console.log("sending") );
   }
}

multimediaAlbumController.ts

export class MultimediaAlbumController{
   $scope;
   static $inject = ['$scope'];
   constructor($scope){ 
      this.$scope = $scope;
   }
   brodRec(){
     this.$scope.$on('prod', () => {
            console.log("receiving");
        });
   }
}

i am getting in console - sengind, but cannot get receiving. What am i doing wrong?


回答1:


please make $scope variable public.

constructor(public scope:ng<IScope>) {
 this.$scope = scope;
}


来源:https://stackoverflow.com/questions/43316719/angularjs-and-typescript-broadcast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!