代码之家  ›  专栏  ›  技术社区  ›  georgeawg

当更新到AngularJS 1.6时,路由演示将停止工作

  •  0
  • georgeawg  · 技术社区  · 8 年前

    当我更新来自 this answer 使用AngularJS1.6时,它停止工作。

    这个 登录 寄存器 链接不再更改视图。

    演示

    var app = angular.module("myApp", ["ngRoute"])
    app.config(function($routeProvider) {
      $routeProvider.when('/', {
          template: `<h1>Login</h1>`,
          controller: 'loginCtrl'
        })
        .when('/register', {
          template: `<h1>Register</h1>`,
          controller: 'RegisterCtrl'
        })
        .otherwise({
          redirectTo: '/'
        });
    
    });
    app.controller('loginCtrl', function($scope) {
      $scope.name = "Login";
    
    });
    app.controller('RegisterCtrl', function($scope) {
      $scope.name = "Register";
    
    })
    <!DOCTYPE html>
    <html ng-app="myApp">
    
    <head>
      <meta charset="utf-8" />
      <title>AngularJS User Registration and Login Example  </title>
    </head>
    
    <body>
      <a href="#/login">Login</a>
      <a href="#/register">Register</a>
      <div class="mainContainer" ng-view></div>
      <script src="//unpkg.com/angular@1.6/angular.js"></script>
      <script src="//unpkg.com/angular-route@1.6/angular-route.js"></script>
    </body>
    
    </html>
    1 回复  |  直到 8 年前
        1
  •  1
  •   Sajeetharan    8 年前

    角度为1.6的路线从 #/state #!/state

    你应该把你的裁判改成:

     <a href="#!/login">Login</a>
     <a href="#!/register">Register</a>
    

    演示

    var app = angular.module("myApp", ["ngRoute"])
    app.config(function($routeProvider) {
      $routeProvider.when('/', {
          template: `<h1>Login</h1>`,
          controller: 'loginCtrl'
        })
        .when('/register', {
          template: `<h1>Register</h1>`,
          controller: 'RegisterCtrl'
        })
        .otherwise({
          redirectTo: '/'
        });
    
    });
    app.controller('loginCtrl', function($scope) {
      $scope.name = "Login";
    
    });
    app.controller('RegisterCtrl', function($scope) {
      $scope.name = "Register";
    
    })
    <!DOCTYPE html>
    <html ng-app="myApp">
    
    <head>
      <meta charset="utf-8" />
      <title>AngularJS User Registration and Login Example  </title>
    </head>
    
    <body>
      <a href="#!/login">Login</a>
      <a href="#!/register">Register</a>
      <div class="mainContainer" ng-view></div>
      <script src="//unpkg.com/angular@1.6/angular.js"></script>
      <script src="//unpkg.com/angular-route@1.6/angular-route.js"></script>
    </body>
    
    </html>