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.
Your code is very unclear. If you want to build a proper service that you can set in the config phase you need a Provider instead, like so:
App.js
angular.module("adf.widget.charts", ["services"])
.config(["chartProvider", function (chartProvider) {
chartProvider.setKey(1232456);
}]);
Service.js
angular.module("services", [])
.provider("chart", [function () {
var googleSheetkey = null;
this.setKey = function (newKey) {
googleSheetkey = newKey;
};
function GoogleSheetkey(key) {
this.googleSheetkey = key;
}
this.$get = [function () {
return new GoogleSheetkey(googleSheetkey);
}];
}]);
Controller.js
angular.module("adf.widget.charts")
.controller("piechartCtrl", ["$scope", "chart",
function ($scope, chart) {
$scope.key = chart.googleSheetkey;
}
]);
Index.html
{{key}}
Plunker
Also, I really suggest you look at this thread regarding Providers, Factories and services:
AngularJS: Service vs provider vs factory
Hope that will help you a little bit.