ui-view未定义,当我使用ui路由时,我的页面是空白的

时间:2017-01-28 04:08:06

标签: angularjs routing angular-ui-router

我无法看到我的索引页面,直到我在控制器中取消注释我的代码。我做错了什么。这是我的示例代码。我已经尝试了所有可能的选项,没有找到我错在哪里

`

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.js"></script>

    <script type="text/javascript">

      var abc = angular.module('myApp', ["ui.router"])

      .config(function($stateProvider,$urlRouterProvider){
          $stateProvider.state('home',{
            template: '<h1>This template is displayed with Ui route </h1>'
          });
          $urlRouterProvider.otherwise('/');
      }).
      controller('myNewCtrl',function($scope,$state){
//        $state.go('home');
      });
    </script>
    <title>My Angular App</title>
</head>
<body ng-app='myApp'>
  <div ng-controller="myNewCtrl">

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

2 个答案:

答案 0 :(得分:0)

<强>样本

load t1 %(foo)
jal t1
...
jal t1
...
jal t1
var myApp = angular.module('myApp', ['ui.router']);
myApp.config(function ($stateProvider, $urlRouterProvider){
    $stateProvider.state("home", {
        url: "#",
        template: "<h1>This template is displayed with Ui route </h1>",
        controller: "myNewCtrl"
      });
});
myApp.controller('myNewCtrl', ['$scope', function($scope) {

}])
 

答案 1 :(得分:0)

工作演示:

&#13;
&#13;
var myApp = angular.module('myApp',['ui.router']);
myApp.config(function ($stateProvider, $urlRouterProvider){
    $stateProvider.state("home", {
        template: "<h1>This template is displayed with Ui route </h1>",
        controller: "myNewCtrl"
      });
});
myApp.controller('myNewCtrl',['$scope','$state', function($scope,$state) {
  $state.go('home');
}]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
<div ng-app="myApp" ng-controller="myNewCtrl">
    <div ui-view></div>
</div>
&#13;
&#13;
&#13;