本文介绍了AngularJS和打字稿广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下问题。我想将相册列表广播到另一个控制器。我的控制器的结构:
父-多媒体控制器,子-多媒体相册控制器。我正在发送变量,但我无法接收变量,我不知道为什么。.
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");
});
}
}
我正在使用控制台-Sengind,但无法获得接收。我在做什么错?
i am getting in console - sengind, but cannot get receiving. What am i doing wrong?
推荐答案
请公开$ scope变量。
please make $scope variable public.
constructor(public scope:ng<IScope>) {
this.$scope = scope;
}
这篇关于AngularJS和打字稿广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!