ng-include添加了div元素

时间:2016-12-11 19:27:02

标签: angularjs

Navigation.html内容

<div class="collapse navbar-collapse" id="app-navbar-collapse">
    <!-- Right Side Of Navbar -->
    <ul class="nav navbar-nav navbar-right">
        <div ng-include="AnnonymousTopHeaderUrl"></div>
    </ul>
</div>

AnnonymousNavigation.html内容

<li>
    <a target="_self" href="#Register">Register</a>
</li>

基本控制器在这里

myApp.controller("BaseController", ["$scope", function($scope) {                 
    $scope.AnnonymousTopHeaderUrl = "App/Include/AnnonymousNavigation.html";        
}]);

当我运行代码时,它显示在Html下面

<ul class="nav navbar-nav navbar-right">
    <!-- ngInclude: AnnonymousTopHeaderUrl -->
    <div ng-include="AnnonymousTopHeaderUrl" class="ng-scope">
        <li class="ng-scope">
            <a target="_self" href="#Register">Register</a>
        </li>
    </div>
</ul>

我期待低于Html

<ul class="nav navbar-nav navbar-right">
    <li>
        <a target="_self" href="#Register">Register</a>
    </li>
</ul>

有没有办法获得预期的Html?

1 个答案:

答案 0 :(得分:0)

您应该将ng-include指示放在ul元素上,这样它就不会在div内创建不必要的ul元素。

<div class="collapse navbar-collapse" id="app-navbar-collapse">
    <ul class="nav navbar-nav navbar-right" ng-include="AnnonymousTopHeaderUrl">
    </ul>
</div>