我被要求将backbone.js应用程序转换为angular.js应用程序,只是想知道Angular是否有类似于backbones.trigger/listenTo的东西,我可以在不知道的情况下发出触发器并触发函数什么函数将处理该发射?
最佳答案
查看 Angular 的文档 here有关 $scope
事件的更多信息,但以下是基础知识:
var myObj = {};
$scope.$emit('someEvent', myObj); // dispatches event upwards through the scope hierarchy
$scope.$broadcast('someEvent', myObj); // dispatches event downwards to child scopes
$scope.$on('someEvent', function(e, data){
// do something with data
});
希望有帮助
关于angularjs - Angular 相当于backbone.js的listenTo/Trigger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20409073/