javascript - What does it mean to pass 2 functions into '.then()'? (Angular.js) -
i'm reading tutorial on angular.js , came across expression:
.then(handlerequest, handlerequest)
i wondering mean pass 2 of same functions .then()?
here's more context:
function mainctrl(user, auth) { var self = this; function handlerequest(res) { var token = res.data ? res.data.token : null; if(token) { console.log('jwt:', token); } self.message = res.data.message; } self.login = function() { user.login(self.username, self.password) .then(handlerequest, handlerequest) } ... } angular.module('app', []) .controller('main', mainctrl) .... })();
and original tutorial can found here: https://thinkster.io/angularjs-jwt-auth
first 1 successcallback , second 1 errorcallback.
// simple request example: $http({ method: 'get', url: '/someurl' }).then(function successcallback(response) { // callback called asynchronously // when response available }, function errorcallback(response) { // called asynchronously if error occurs // or server returns response error status. });
promises bit complex pattern understand. best resource me is
Comments
Post a Comment