javascript - How to pass values between service and controllers -


how can 1 pass values services controllers? have been reading stackoverflow questions regarding , none of solutions seem solve problem. trying access google spreadsheets using tabletop.js when console.log services can see values when try access spreadsheet values controller following error: chartservice.getproperty not function

the code getting url of spreadsheet works fine. method. not sure doing wrong here.

controller

angular.module('myapp')   .controller('piechartctrl', function (chartservice, $scope, config) {     $scope.values = chartservice.getproperty();    }); 

service.js

angular.module('myapp') .service('chartservice', function(){   return {      geturl: function init(path) {         tabletop.init( { key: path,                          callback: showinfo,                          simplesheet: true } )      }   }  function showinfo(data, tabletop) {     return{       getproperty: function(){         return data       },       setproperty: function(value){         data = value;       }      }   } }); 

this service, thing see returning geturl. thing able access controller chartservice.geturl function.

service('chartservice', function () {     return      {         geturl: function init(path)         {             tabletop.init({                 key: path,                 callback: showinfo,                 simplesheet: true             })         }     }      function showinfo(data, tabletop)     {         return          {             getproperty: function ()             {                 return data             },             setproperty: function (value)             {                 data = value;             }             }     } }); 

to working, while don't think ideal solution should work...

service('chartservice', function () {     var returnobject =      {         geturl: function init(path)         {             tabletop.init({                 key: path,                 callback: showinfo,                 simplesheet: true             })         },         resultvalue: {}     }      function showinfo(data, tabletop)     {         return          {             getproperty: function ()             {                 return data             },             setproperty: function (value)             {                 data = value;                 returnobject.resultvalue = value;             }             }     }      return returnobject }); 

then replace chartservice.getproperty() chartservice.resultvalue although in no synchronous.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -