<! - ngView:undefined - >是什么意思

时间:2013-12-22 19:24:23

标签: angularjs javascript-framework

我得到这样一个dom:

<div class="row">
  <::before>
    <div class="col-lg-12">
      <!-- ngView: undefined -->
        <ng-view class="ng-scope">
          <h1 class="ng-scope">Hello world</h1>
        </ng-view>
    </div>
  <::after>
</div>

做什么:

    <!-- ngView: undefined -->

意思?

一切似乎工作正常,但我不喜欢这个评论,因为似乎某些东西不能正常工作?

模板看起来像这样:

<h1>Hello world</h1>

并且配置如下:

var myApp = angular.module('myApp', [
'ngRoute',

.....

]);

myApp.config(['$routeProvider', function($routeProvider){
$routeProvider.when('/my_template', {templateUrl: '/web-angular/my_template.html'})
.when( .....  );
}]);

3 个答案:

答案 0 :(得分:6)

将'ng-view'指令放在div或span中。比如...

<div ng-view></div>
<span ng-view></span>

在这里查看IE限制AngularJS IE Guide并查看数字3和4.从此,我认为这只是一个警告。引起你注意的东西,就像它一样。请注意,在您的课程中声明ng-view仍然有效,但您将在标记中收到相同的警告消息。

答案 1 :(得分:2)

对于其他遇到此问题并且没有其他答案运气的人,我遇到了这个问题,因为我没有将控制器作为模块的依赖项。

angular.module('myApp', ['module-for-missing-page'])

包含此依赖项可以正确加载视图。

答案 2 :(得分:0)

在锚标记中注入你的视图。就像这个

<div>
<a href="#/home"> Home</a>
    <a href ="#/students"> Students </a>
    <a href="#/courses"> Courses </a> 
    <ng-view>  </ng-view> 
</div>



 var app = angular.module("MyApp", ["ngRoute"])
                 .config(function ($routeProvider) {
                     $routeProvider
                         .when("/home", {
                             templateUrl: "Templates/home.html",
                             controller: "homeController"
                         })
                         .when("/courses", {
                              templateUrl: "Templates/courses.html",
                              controller: "courseController"
                         })
                        .when("/students", {
                            templateUrl: "Templates/students.html",
                            controller: "studentsController"
                         })
                 })

                  .controller("homeController", function ($scope) {
                      $scope.message = "I am in home controller";
                  })
                 .controller("courseController",function($scope){
                      $scope.message = "I am in courses controller";
                 })
                 .controller("studentsController", function ($scope) {
                      $scope.message = "I am in students controller";
                 })

并检查您是否放置了正确的ng-route链接。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js">
 </script>
相关问题