Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. var app = angular.module('myWebservice', ['ngCookies']).run(
  2. function($rootScope) {
  3. $rootScope.authToken = null; });
  4.  
  5. app.controller('UserController', function($cookieStore, $scope, $location,
  6. $routeParams, $http, $timeout, $rootScope) {
  7.  
  8. $scope.login= function() {
  9.  
  10. $http.defaults.headers.post = {'Accept' : 'application/json',
  11. 'Content-Type' : 'application/json'};
  12.  
  13. $http.post('/myServise/api/user/login-user', {
  14. emailId : $scope.username,
  15. password : $scope.password
  16.  
  17. }).success(function(data, status) {
  18. if (status == 200) {
  19. $rootScope.authToken = data.object.authToken;
  20. }).error(function(data, status) {
  21. console.debug(data);});
  22. }// Else end
  23.  
  24. };// End Login
  25.  
  26.  
  27. app.controller('MerchantController', function($cookieStore, $scope, $location,
  28. $routeParams, $http, $timeout, $rootScope) {
  29.  
  30. $scope.getRootScopeValues = function()
  31. //$scope.getRootScopeValues = function($rootScope)
  32. {
  33. $scope.token = $rootScope.authToken;
  34. console.log($scope.token);// Undefined
  35. console.log($rootScope.authToken);// Undefined
  36. }
  37. });
  38.  
  39. .config(function($routeProvider, $locationProvider) {
  40. $routeProvider
  41. .when('/your/route', {
  42. templateUrl: 'book.html',
  43. controller: 'BookController',
  44. resolve: {
  45. token: function() {
  46. //return a promise with the token here
  47. }
  48. }
  49. })
  50.  
  51. app.controller('MerchantController', function($cookieStore, $scope, $location,
  52. $routeParams, $http, $timeout, $rootScope) {
  53.  
  54. $rootScope.tokenPromise.then( function(token){
  55. console.log(token); //depends on the returned data structure
  56.  
  57. } )
  58.  
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement