【发布时间】:2016-01-15 11:54:10
【问题描述】:
我正在尝试为angular dashboard framework、sample widgets can be found here 制作一个小部件。我在尝试将 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>
此时我只是想从piechartCtrl 获取console.log 数据,但我无法这样做。我在控制台中唯一得到的是
您传递了一个新的 Google 电子表格网址作为键!试图解析。 tabletop.js:400 使用密钥 1voPzG2Sha-BN34bTK2eTe-yPtaAW2JZ16lZ3kaDWxCs 初始化
这意味着当我输入工作表 url 时,工作表已被处理,但我无法从这一点开始。谷歌表格网址
https://docs.google.com/spreadsheets/d/1voPzG2Sha-BN34bTK2eTe-yPtaAW2JZ16lZ3kaDWxCs/pubhtml
【问题讨论】:
标签: javascript jquery angularjs tabletop.js