我正试图为角形仪表板框架,这里可以找到样例小部件制作一个小部件。当我试图在小部件中集成tabletop.js时,我感到震惊。我不知何故无法得到控制器中的数据。
我的代码:
use strict;
angular.module('adf.widget.charts', ['adf.provider', 'highcharts-ng'])
.config(function(dashboardProvider){
var widget = {
templateUrl: '{widgetsPath}/charts/src/view.html',
reload: true,
resolve: {
/* @ngInject */
urls: function(chartService, config){
if (config.path){
return chartService.getSpreadsheet(config.path);
}
}
},
edit: {
templateUrl: '{widgetsPath}/charts/src/edit.html'
}
};
dashboardProvider
.widget('piechart', angular.extend({
title: 'Custom Piechart',
description: 'Creates custom Piechart with Google Sheets',
controller: 'piechartCtrl'
}, widget));
});服务和控制器
'use strict';
angular.module('adf.widget.charts')
.service('chartService', function ($q){
return {
getSpreadsheet: function init(path){
var deferred = $q.defer();
Tabletop.init({
key: path,
callback: function(data, Tabletop) {
deferred.resolve([data, Tabletop]);
},
simpleSheet: true,
debug: true
});
}
}
})
.controller('piechartCtrl', function ($scope, urls) {
$scope.urls = urls;
console.log(data) //I get error here data is not defined
});edit.html
<form role="form">
<div class="form-group">
<label for="path">Google Spreadsheet URL</label>
<input type="text" class="form-control" id="path" ng-model="config.path" placeholder="Enter URL">
</div>
</form>view.html
<div>
<div class="alert alert-info" ng-if="!chartConfig">
Please insert a repository path in the widget configuration
</div>
<div ng-if="chartConfig">
<highchart id="chart1" config="chartConfig"></highchart>
</div>
</div>此时,我只是尝试从console.log中获取piechartCtrl数据,但我无法做到这一点。我在控制台里唯一能得到的就是
你传递了一个新的Google电子表格url作为关键!试图解析。用键1voPzG2Sha-BN34bTK2eTe-yPtaAW2JZ16lZ3kaDWxCs初始化tabletop.js:400
这意味着,当我输入工作表url时,工作表将被处理,但我不能从这里开始。Googlesheet表URL
https://docs.google.com/spreadsheets/d/1voPzG2Sha-BN34bTK2eTe-yPtaAW2JZ16lZ3kaDWxCs/pubhtml
发布于 2016-01-15 12:09:56
您可以使用$broadcast服务并在其中传递对象。例如,您可以通过以下方式从控制器广播事件:
$rootScope.$broadcast("sendingItemFromService",{"item": yourValue});在其他控制器中,您甚至可以通过以下方式捕捉到这一点:
$scope.$on("sendingItemFromService", function(event, args) {
console.log(args.item);
});https://stackoverflow.com/questions/34810521
复制相似问题