angular 从外部文件向指令广播数据
angular broadcast data to directive from external file
我正在尝试将数据从外部 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);
});
希望这对您有所帮助。
我正在尝试将数据从外部 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);
});
希望这对您有所帮助。