我有以下问题。我想将专辑数组广播到另一个 Controller 。我的 Controller 的结构: 父级 - 多媒体 Controller ,子级 - 多媒体相册 Controller 。我正在发送变量,但我无法接收 i,实际上不知道为什么..
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");
});
}
}
我正在进入控制台 - sengnd,但无法接收。我做错了什么?
最佳答案
请将 $scope 变量公开。
constructor(public scope:ng<IScope>) {
this.$scope = scope;
}
关于javascript - AngularJS 和 typescript 广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43316719/