2017-04-10 70 views
0

我有以下問題。我想將專輯陣列廣播到另一個控制器。我的控制器的結構: 父 - multimediaController,子 - multimediaAlbumController。我送的變量,但我不能接受我,不知道爲什麼竟然..AngularJS和打字稿廣播

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中,但無法接收。我究竟做錯了什麼?

+1

您何時/在哪裏調用'brodRec'?我只是將'$ scope。$ on'調用移動到構造函數 – Phil

+0

因此,試着將$ scope。$移動到construcotr,咋?將嘗試 – qwerty1234567

+0

好的作品。非常感謝:) – qwerty1234567

回答

0

請將$ scope變爲public。

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

菲爾找到了一個解決方案。不管怎樣,謝謝 ;) – qwerty1234567