Angular $ broadcast不起作用

时间:2016-03-24 12:47:31

标签: javascript angularjs

当我尝试播放活动时:

var text:String = "hello";
var srcBA:ByteArray;
var desBA:ByteArray;

var rsaKey:RSAKey;
var encodedB64:String;

// ENCODING 

srcBA = new ByteArray();
srcBA.writeUTFBytes(text);

desBA = new ByteArray();

rsaKey = PEM.readRSAPrivateKey( readPrivateKey() );
rsaKey.sign(srcBA, desBA, srcBA.length);

encodedB64 = Base64.encodeByteArray(desBA);
trace("Original: " + text);
trace("Encoded: " + encodedB64 );


// DECODING

var srcBA2:ByteArray = new ByteArray();
var desBA2:ByteArray = new ByteArray();
var rsaKey2:RSAKey = PEM.readRSAPublicKey( readPublicKey() );

srcBA2 = Base64.decodeToByteArray( encodedB64 );

rsaKey2.verify(srcBA2, desBA2, srcBA2.length);

trace("Decoded: " + desBA2.toString() );

它不会被$scope.selectCategory = function(cat) { $scope.$broadcast('Cat', {catID: cat}); } 抓住:

$scope.$on

问题:我成功将变量传递到广播,但 $ scope.on 回调永远不会被触发。

1 个答案:

答案 0 :(得分:1)

你需要在$ rootScope上播放$:

$scope.selectCategory = function(cat) {
                                // $location.path('/films/' + cat);
                                $rootScope.$broadcast('Cat', {catID: cat});
                                console.log(cat);
                            }

其余的代码应该没问题。

参考:Official Angular Guide