ui-router没有显示我的观点

时间:2015-04-04 15:25:18

标签: angularjs angular-ui-router

的index.html:

<!doctype html>
<html ng-app ng-csp>
  <head>
    <meta charset="UTF-8">
    <title>Presently</title>
    <link rel="stylesheet" href="app/styles/angular-csp.css">
    <!--<link rel="stylesheet" href="css/main.css">-->

    <script src="assets/dependencies/angular/angular.min.js"></script>
    <script src="assets/dependencies/angular-ui-router/release/angular-ui-router.js"></script>

    <script src="main.js"></script>

    <script src="app/states/home/home.controller.js"></script>
    <script src="app/states/home/favs/fav.controller.js"></script>
  </head>
  <body>
    hello {{'foo'.length}}

    <div ui-view></div>
  </body>
</html>

main.js:

console.log('main.js');

var myApp = angular.module('myApp', ['ui.router'])
.config(['$stateProvider', '$urlRouteProvider'
  , function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise("/");

  $stateProvider
    .state('state1', {
      url: "/",
      template: "home"
    });
}]);

console.log(myApp);

因此控制台日志显示main.js和应用程序,但视图中没有呈现任何内容。我希望看到“家”这个词

1 个答案:

答案 0 :(得分:1)

您输错了$urlRouteProvider而不是$urlRouterProvider

.config(['$stateProvider', '$urlRouteProvider'
, function($stateProvider, $urlRouterProvider) {

我在this working plunker

中修复了这个问题
.config(['$stateProvider', '$urlRouterProvider'
, function($stateProvider, $urlRouterProvider) {

检查Router

中的 $urlRouterProvider