javascript - what is wrong with this code in angular? -


in console error coming "getiddata not defined" wrong code. here deal service , getiddata function in service.

$scope.edituserdetail = function edituserdetail(){         $scope.showeditview = !$scope.showeditview;         $scope.showsubmitview = !$scope.showsubmitview;         console.log(deal);         deal.getiddata().then(function successcb(data){             $scope.editidoptionsdata=data;           }); }; 

please check working example here: demo

you forget return service object service.

i.e

write following code in service,

return service; 

i.e

angular.module('account').service('deal', function deal($http, accountconfiguration, $q, $log, httphelper) {      var service = {};      var baseurl = account.app.url;      service.getiddata = function(data, accountid, decisionmakerdetail) {             var def = $q.defer();             var url = baseurl + '/api/accountsusers/' + accountid + '?role=' + decisionmakerdetail;             httphelper._$http({                       method: 'post',                       url: url,                       data: data,                       def: def              }, function(resp) {                  def.resolve(resp.msg);              });              return def.promise;       };        return service; }); 

or using service can write using this

angular.module('account').service('deal', function deal($http, accountconfiguration, $q, $log, httphelper) {       var baseurl = account.app.url;      this.getiddata = function(data, accountid, decisionmakerdetail) {             var def = $q.defer();             var url = baseurl + '/api/accountsusers/' + accountid + '?role=' + decisionmakerdetail;             httphelper._$http({                       method: 'post',                       url: url,                       data: data,                       def: def              }, function(resp) {                  def.resolve(resp.msg);              });              return def.promise;       };    }); 

for more information please check - services


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -