【发布时间】:2016-01-15 15:17:16
【问题描述】:
如何从 angular.js 中的服务 $rootScope.$broadcast
在 $rootScope.$broadcast 之后,我想从控制器访问 console.log(data),但我在控制台中看不到任何内容
我的代码:
'use strict';
angular.module('adf.widget.charts')
.factory('chartService', function ($q, $rootScope){
return {
getSpreadsheet: function init(path){
var deferred = $q.defer();
Tabletop.init({
key: path,
callback: function(data, Tabletop) {
$rootScope.$broadcast(data)
},
simpleSheet: true,
debug: true
});
}
}
})
.controller('piechartCtrl', ['$scope', 'chartService', function($scope, chartService, urls) {
$scope.$on('getSpreadsheet', function(data){
console.log(data)
});
}]);
【问题讨论】:
-
阅读
$broadcast的文档
标签: javascript jquery angularjs