Friday, 15 January 2010

angularjs - angular ui router set custom header for request -



angularjs - angular ui router set custom header for request -

in application, utilize authorization headers, , after user action (login), want set each request additional header.

var app = angular.module('app', ['ui.router']); app.config(function($stateprovider, $urlrouterprovider) { $urlrouterprovider.otherwise("/"); $stateprovider.state("login", { url: "login", templateurl: "common/login" }) .state("secured", { url: "secured", templateurl: "secured/secured" }); });

when user come in name , password, in backend of application set x-auth-header , homecoming it.

//frontend controller login form

usercontrollers.controller('usercontroller', ['$scope', '$http', '$state', function($scope, $http, $state) { //on button click send info user $scope.send = function(user) { $http.post('api/login', user). success(function() { //all ok, should alter state secured $state.go("secured"); }). error(function() { //handler errors }); } }]);

when after success user input alter $state, want send x-auth-header alter state, possible ui router?

and how restrict secured area, if user browser alter url on /#/secured?

i don't know if still have same problem, guy @ http://onehungrymind.com/winning-http-interceptors-angularjs/ solved of problems: router-ui doesn't remove alternative utilize classic angularjs' $http interceptors! hope works

angularjs angular-ui-router

No comments:

Post a Comment