angularjs - Getting error "then is not a function" in angular js -
i trying call data file using $http .i make factory , result in controller .i want declare both success , error method .but getting error accountdetailservice.callaccountdetailservice.then not function here code
http://plnkr.co/edit/egapwudpgknwdnozmjwu?p=preview
angular.module('ionicapp', ['ionic'])   .controller('showhidecntr', function($scope, $window,accountdetailservice) {     $scope.hgt = $window.innerheight / 3;     //alert($scope.hgt)     accountdetailservice.callaccountdetailservice.then(function(data){       console.log(data);     }).error(function(data){        console.log("error"+data);     })    }).factory('accountdetailservice',['$http','$q', function($http, $q) {          return {             callaccountdetailservice: function(callback){                 $http.get('default.json').success(callback).error(callback);             }         };      }])   ;
the promises works when return callback object. there 2 way fix problem.
1- change factory code code:
            return $http.get('default.json').success(callback).error(callback);   2- can use success instead of , remove success , error callback factory.
if it's me , choose option 1, because it's more clear , easy understand.
good luck , have fun.
Comments
Post a Comment