简体   繁体   English

AngularJS使用$ location.path和ngRoute

[英]AngularJS working with $location.path and ngRoute

I have this $location.path redirection: 我有这个$location.path重定向:

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 发生重定向时,它将用户重定向到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.. 所以我正在尝试使用ngRoute但无法使其正常工作。

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时应使用的路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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