Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('myWebservice', ['ngCookies']).run(
- function($rootScope) {
- $rootScope.authToken = null; });
- app.controller('UserController', function($cookieStore, $scope, $location,
- $routeParams, $http, $timeout, $rootScope) {
- $scope.login= function() {
- $http.defaults.headers.post = {'Accept' : 'application/json',
- 'Content-Type' : 'application/json'};
- $http.post('/myServise/api/user/login-user', {
- emailId : $scope.username,
- password : $scope.password
- }).success(function(data, status) {
- if (status == 200) {
- $rootScope.authToken = data.object.authToken;
- }).error(function(data, status) {
- console.debug(data);});
- }// Else end
- };// End Login
- app.controller('MerchantController', function($cookieStore, $scope, $location,
- $routeParams, $http, $timeout, $rootScope) {
- $scope.getRootScopeValues = function()
- //$scope.getRootScopeValues = function($rootScope)
- {
- $scope.token = $rootScope.authToken;
- console.log($scope.token);// Undefined
- console.log($rootScope.authToken);// Undefined
- }
- });
- .config(function($routeProvider, $locationProvider) {
- $routeProvider
- .when('/your/route', {
- templateUrl: 'book.html',
- controller: 'BookController',
- resolve: {
- token: function() {
- //return a promise with the token here
- }
- }
- })
- app.controller('MerchantController', function($cookieStore, $scope, $location,
- $routeParams, $http, $timeout, $rootScope) {
- $rootScope.tokenPromise.then( function(token){
- console.log(token); //depends on the returned data structure
- } )
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement