2016-07-14 66 views
2

我无法使用ui路由器进行路由。它对ng-route有帮助,所以我一定错过了一些基本的东西。没有错误,但我没有任何看法。angular-ui-router不起作用

下面的代码确实工作(除另有声明):

angular.module("employeesApp", ["ui.router"]) 
.config(function ($stateProvider, $urlRouterProvider) { 
    $stateProvider 
     .state('employeeList', { 
      url: "/employees", 
      templateUrl: "components/employee_list/employeeListView.html", 
     }); 

    $urlRouterProvider.otherwise("/employees"); 
}); 

下面的代码不工作:

angular.module("employeesApp", ["ngRoute"]) 
.config(function ($routeProvider) { 
    var employeeListRoute = { 
     templateUrl: "components/employee_list/employeeListView.html" 
    }; 

    var otherwiseRoute = employeeListRoute; 

    $routeProvider 
     .when("/employeeList", employeeListRoute) 
     .otherwise(otherwiseRoute); 

这里是我的index.html(省略不相关元素):

<!DOCTYPE html> 
<html lang="en" ng-app="employeesApp"> 
<head> 
    <title></title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js"></script> 

    <script src="app.route.js"></script> 
    <script src="components/employee_list/employeeListCtrl.js"></script> 
</head> 
<body> 
    <div> 
     <ng-view /> 
    </div> 
</body> 
</html> 

我在做什么w rong在尝试使用ui-router时?

+0

在控制台中的任何错误被加载到获得路由器?你有没有包含'angular-ui-router.js'? –

+0

@Pankaj Parkar在控制台中没有错误,并且我包含了angular-ui-router.js。作为证明:其他声明确实起作用。 – Alon

+2

您很有可能错过了ui-view指令:'

'。你有在任何地方加载视图的'ui-view'吗? –

回答

3

正如@AminMeyghani已经说了,你应该使用的ui-view代替ng-view指令知道,相对应视图里面ui-view指令

<div> 
    <ui-view></ui-view> 
</div> 

Demo here