javascript - Angular.js service factory $http.get not calling my service -
i trying data in service factory. nothings happen.it executed code. nothings happened. dont know why?
here service code:
'use strict'; app.factory('accountservice', function($http, $location, $rootscope) { return { accounts: function() { $http.get('http://localhost:29045/accountoperation.svc/getaccounts').success(function(data, status, headers, config) { console.log(status); var $promise = data; console.log(data); }).error(function(data, status, headers, config) { }); } } });
here controller(calling factory here):
'use strict'; app.controller('accountcontroller', function($scope, accountservice, $rootscope) { $scope.accounts = function() { accountservice.accounts(); } });
also didnt error.
on account function not creating promise or returning anything. try:
app.factory('accountservice', function($http, $location, $rootscope) { return { accounts: function() { return $http.get('http://localhost:29045/accountoperation.svc/getaccounts'); } } });
this returns promise , can handle anywhere call acccount function or create promise inside function , return it. inside success or error methods resolve or reject it.
Comments
Post a Comment