简体   繁体   中英

AngularJS working with $location.path and ngRoute

I have this $location.path redirection:

myapp.controller('registerCtrl', function ($scope, $location, regService) {
  $scope.register = function() {
    $('#regbutton').prop('disabled','disabled');
    regService.createUser($scope.email, $scope.password, function(id) {
      if (id) {
        $('#register').modal('hide');
        $location.path('/account');
      }
    });
  }
})

When the redirection occurs it redirects the user to http://myapp.com/#/account

Now I want to display a different template to show the user account. So I'm trying to use ngRoute but cannot get it to work properly..

myapp.config(['$routeProvider', '$locationProvider', '$provide',
  function ($routeProvider, $locationProvider, $provide) {
    console.log('in');
    $provide.decorator('$sniffer', function($delegate) {
      $delegate.history = false;
      return $delegate;
    });
    $routeProvider.
      when('/account', {
        templateUrl: 'account.html',

        resolve: {
          // I will cause a 1 second delay
          delay: function ($q, $timeout) {
            console.log('in resolve');
            var delay = $q.defer();
            $timeout(delay.resolve, 1000);
            return delay.promise;
          }
        }
      });
    $locationProvider
      .html5Mode(true)
      .hashPrefix('');
  }]);

在配置when()函数为/account时应使用的路由

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM