I am building a small widget using angular that takes Google sheet Ids given by user and publishes the output in nice json format. The problem is that my code does nothing.
Working example here
Example path:
https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html
Best way is with Promise
Use q framework ($q service)
Remove the logic from the controller to the service
App
angular.module('myApp', []);
Service
angular.module("myApp")
.service("chartService", function($q) {
return {
getSpreadsheet: function init(path) {
var deferred = $q.defer();
//if no path use the config key
Tabletop.init({
key: path,
callback: deferred.resolve,
simpleSheet: true
});
return deferred.promise;
}
}
});
Controller
angular.module('myApp')
.controller('piechartCtrl', ['$scope', 'chartService', function($scope, chartService) {
$scope.getSheet = function() {
chartService.getSpreadsheet($scope.googleSheetPath).then(function(data) {
$scope.data = data;
})
}
}]);
index.html
{{data}}