angularjs - Console error, not sure way -
i getting error.. not sure what's problem..
typeerror: statisticsservice.getstatisticsfromserver not function
i cant seem see problem, not sure i'm doing wrong
this controller
app.controller('statisticsctrl', ['$scope', '$auth', 'statisticsservice', function ($scope, $auth, statisticsservice) { var token = $auth.gettoken(); console.log('statisticsctrl init'); function run() { var data = { token: token, timestamp_from: moment(new date()).unix()-30 * 24 * 3600, timestamp_till: moment(new date()).unix(), order: 'duration_minutes', limit: 20 }; // statisticsservice.getstatisticsfromserver(data).then(function (response) { console.log('syncstatistics', (response)); $scope.statistics = response; // $scope.statistics = statisticsservice.buildstatsusers(response.data); // jason comes here }, function (error) { console.error(error); }); } run(); }]);
this server
app.service('statisticsservice', ['apiclient', '$q', '$rootscope', '$timeout', function (apiclient, $q, $rootscope, $timeout) { var self = this; self.getuserprofiles = function (stats) { var emails = []; (var = 0; < stats.length; i++) { emails.push(stats[i].email); } console.log(emails); var data2 = { token: data.token, profile_emails: emails }; apiclient.getuserprofiles(data2).then(function (response2) { console.log('getuserprofiles', (response2)); if (response2.data.length === 0 || response2.result !== "success") { // todo: show error deferred.reject(response2); } var stats2= response2.data; deferred.resolve(stats);//3 } ); self.getstatisticsfromserver = function (data) { var deferred = $q.defer(); //1 apiclient.getstatstopmeeters(data) .then(function (response) { //2 console.log('externalapiconnect', response); if (response.data.length === 0 || response.result !== "success") { // todo: show error deferred.reject(response); } var stats = response.data; stats = self.getuserprofiles(stats); deferred.resolve(stats);//3 } , function (error) { deferred.reject(error); console.error(error); }); return deferred.promise; //4 }; }; }]);
you're defining self.getstatisticsfromserver
inside function self.getuserprofiles
. so, function indeed doesn't exist in service until call getuserprofiles()
@ least once. , it's replaced @ each invocation. doubt that's want.
Comments
Post a Comment