angularjs的事件 $broadcast and $emit and $on

来源:互联网 发布:c语言怎么ab之间求素数 编辑:程序博客网 时间:2024/06/01 07:31

事件是解耦良器,angularjs提供了很方便的事件机制。发送事件,可以使用$scope.$broadcast('name', 'args')或者是$scope.emit('name', 'args'),而接受事件只能用$scope.$on。

$broadcast与$emit的区别:$broadcast是发送者向子scope发送事件的方法,而$emit是向父scope发送事件的方法。

0 0