问题
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