Ng-包括关于Controller编译的评论

时间:2016-07-12 18:35:40

标签: javascript html angularjs gruntjs

我正在创建一个有角度的应用,并且有一个奇怪的问题。

这是我的控制者:

angular.module('clientApp')
.controller('AdminCtrl', function ($scope) {


});

这是我的观点:

    <div class="admin" ng-controller="AdminCtrl">
      <div ng-include="'/views/partials/header-admin.html'"></div>
      <p>This is the admin view.</p>
    </div>

当我运行应用程序时,ng-include出现了注释:

<!-- ngInclude: '/views/partials/header-admin.html' -->

但如果我删除了我的视图的ng-controller,它会毫无问题地呈现ng-include:

 <div class="admin" >
    <div ng-include="'/views/partials/header-admin.html'"></div>
    <p>This is the admin view.</p>
</div>

HTML:

<div ng-include="'/views/partials/header-admin.html'" class="ng-scope"><header class="ng-scope">
    <div class="logo">
    <div class="user-preferences"></div>
</div></header>
<nav class="left-nav ng-scope">
    <ul>
        <li>
            <a href="#">Dashboard</a>
        </li>
        <li>
            <a href="#">Temas (Materias)</a>
        </li>
        <li>
            <a href="#">Sitios</a>
        </li>
        <li>
            <a href="#">Grupos</a>
        </li><!-- 
        <li>
            <a href="#">Dashboard</a>
        </li> -->
    </ul>
</nav></div>

1 个答案:

答案 0 :(得分:0)

首先,您的部分视图代码中存在错误。你不能让ng-include指向同一个文件:

<div ng-include="'/views/partials/header-admin.html'" class="ng-scope"><header class="ng-scope">

如果你这样做,你必须回复一些错误,如:

enter image description here

因为你用包含文件创建了一个无限的bucle,所以你要做的第一件事是删除你的部分文件中的include。我认为这不应该有任何问题!