angularjs - The correct definition of data -
i have code, when run error of "referenceerror: data not defined" have defined data in several ways nothing seem correct. thing when think data declared in api (no?).. appreciate help..
app.service('statisticsservice', ['apiclient', '$q', '$rootscope', '$timeout', function (apiclient, $q, $rootscope, $timeout) { var self = this; 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 }; self.getuserprofiles = function (stats) { var deferred = $q.defer(); 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 stats = response2.data; deferred.resolve(stats);//3 } ); }; }]);
this of apiclient page
app.service('apiclient', ['$http', '$q','$rootscope', function ($http, $q, $rootscope) { var canceler = $q.defer(); var request = function (apimethod, apiresponse) { switch (apimethod) { case 'set_meeting_note': case 'get_meeting_details': case 'get_account_details': case 'get_availability': case 'get_best_time': case 'get_participants_statuses': case 'check_user_verified_send_email': case 'get_participants_statuses': case 'get_user_profiles': case 'set_calendar_settings': case 'sync_external_apis': $rootscope.showloader = false; break; default: $rootscope.showloader = true; break; } var config = { method: 'post', url: apipath + apimethod, data: apiresponse, headers: {'content-type': 'application/x-www-form-urlencoded'}, withcredentials: true, timeout: canceler.promise }; $http(config).success(function (data) { $rootscope.showloader = false; if (data.message === undefined) { deferred.resolve(data); } else { deferred.reject(data); } }).error(function (data, status, headers, config) { $rootscope.showloader = false; deferred.reject(data); }); return deferred.promise; }; return { getstatstopmeeters: function (data) { return request('get_stats_top_meeters',data ); }, getuserprofiles: function(data){ return request('get_user_profiles',data); }, }
Comments
Post a Comment