我正在尝试将数据从外部 js 文件传递到指令 Angular 文件。 这就是我正在做的事情。
在我的外部 js 文件上:
var formatData = {
id: 1,
state: 'moving'
}
angular.element(document).scope().$broadcast('sendData', formatData);
在我的指令中:
scope.$on('API.sendData', function(formatData) {
console.dir(formatData);
});
记录了什么:
帮忙?
最佳答案
您应该使用监听器函数的第二个参数,第一个参数是事件数据。
scope.$on('API.sendData', function(event, formatData) {
console.dir(formatData);
});
希望这有帮助。
关于javascript - 从外部文件到指令的 Angular 广播数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666835/