javascript - Angular JS - My controller function its never return after execute my service script -
the process login user on app working. connecting server , returned 200 status, it's working fine. after service finish task, controller not executing lines:
controller:
loginservice.signin(formdata, function(res) { console.log('this message never prints'); });
does have idea how resolve this? maybe interceptor involved in behavior. here scripts:
app.js
'use strict'; var app = angular.module('myapp', [ 'ngroute', 'ngstorage', 'ngcookies', 'myapp.controllers', 'myapp.services' ]); app.config(['$routeprovider', '$httpprovider', function ($routeprovider, $httpprovider) { $routeprovider .when('/', { templateurl: 'views/logueo.html', controller: 'logincontroller' }) .when('/principal', { templateurl: 'views/principal.html' }) .otherwise({ redirectto: '/' }); }]);
controller.js
angular.module('myapp.controllers', []) .controller('logincontroller', ['$rootscope', '$scope', '$http', '$location', '$localstorage', 'loginservice', '$cookies', function ($rootscope, $scope, $http, $location, $localstorage, loginservice, $cookies) { $scope.signin = function() { var formdata = { username: $scope.username, password: $scope.password }; loginservice.signin(formdata, function(res) { // problem here. // not executing rest of lines. // usuario incorecto. if (res.type == false) { console.log("false " + res.data); } // usuario correcto. else { window.location = "#/principal.html"; } }, function() { $rootscope.error = "error en el logueo del usuario"; }); } }]);
service.js
'use strict'; angular.module('myapp.services', []) .factory('loginservice', ['$http', '$localstorage', 'tokenstorage', function ($http, $localstorage, tokenstorage) { // executing return { signin: function(data, success, error) { $http.post( 'http://myweb.com/api' + '/login', data ).success( function (result, status, headers) { console.log("logueado"); }).error(function (data, status, headers, config) { console.log("error. " + data); }) } }; }]);
you not calling success function passed signin function:
signin: function(data, success, error) { $http.post( 'http://myweb.com/api' + '/login', data ).success( function (result, status, headers) { success(result); console.log("logueado"); tokenstorage.store(headers('x-auth-token')); }).error(function (data, status, headers, config) { console.log("error. " + data); }) }
Comments
Post a Comment