angularjs ng包括

ou6hu8tu  于 2021-09-29  发布在  Java
关注(0)|答案(4)|浏览(377)

在使用时,我面临以下问题 ng-inculde 用angularjs。引导汉堡图标不工作。但是如果我不使用 ng-include 它工作得非常好。我做错什么了吗?。
在使用之前,我是否需要先进行任何设置 ng-include ?.

主html

...
<body>
<ng-include src="'../Content/Shared/Header.html'"></ng-include>
<ng-view></ng-view>
</body>
....

包括html

<header>
<div class="container">
    <div class="row element-holder">
        <div class="col-md-2 col-sm-4 col-12">
            <a href="../main/index.html" class="text-logo-holder">
                <span class="text">My Project</span>
            </a>
        </div>
        <div class="col-md-4 col-sm-6 col-12">
            <form ng-submit="searchProducts()" class="search-holder">
                <input type="text" class="form-control" placeholder="Search Collection...." list="_items" ng-model="searchText" ng-keyup="searchItemNames()" autocomplete="off" />
                <datalist id="_items">
                    <option ng-repeat="result in results" value="{{result}}">{{result}}</option>
                </datalist>
                <button type="submit" class="btn btn-primary"><i class="fas fa-search"></i></button>
            </form>

        </div>
        <div class="col-md-6 col-sm-2 col-12">
            <nav class="navbar navbar-expand-lg float-right">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <img src="../Content/dist/images/icon-header-menu.png" />
                </button>

                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Discover</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">About Us</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Help</a>
                        </li>
                        <li class="nav-item btn-nav-item">
                            <a class="nav-link" href="" ng-click="logout()" ng-show="isSignedIn">Logout</a>
                            <a class="nav-link" href="" ng-click="signin()" ng-show="!isSignedIn">Sign In</a>
                        </li>
                        <li class="nav-item">
                            <a id="menu-link" class="nav-link" href="#">
                                <img src="../Content/dist/images/icon-header-menu.png" />
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <div class="mobile-nav  float-right">
                <a id="menu-link-mobile" class="nav-link" href="#">
                    <img src="../Content/dist/images/icon-header-menu.png" />
                </a>
            </div>
        </div>
    </div>
</div>

<div id="sidebar-menu" class="side-menu-content">
    <a href="#" id="menu-close" class="menu-close">&nbsp; </a>
    <ul class="menu-holder">
        <li>
            <a href="#" class="menu-item row">
                <div class="col-3 icon-holder">
                    <img src="../Content/dist/images/icon-inbox.png" />
                </div>
                <div class="col-9">
                    Inbox
                </div>
            </a>
        </li>

        <li>
            <a href="#" class="menu-item row">
                <div class="col-3 icon-holder">
                    <img src="../Content/dist/images/icon-purchase.png" />
                </div>
                <div class="col-9">
                    Purchases
                </div>
            </a>
        </li>
    </ul>

    <div class="button-holder row">
        <div class="col-6 pl-default pr-default" ng-show="!isSignedIn">
            <input type="submit" class="btn btn-primary" value="Login/Sign Up" ng-click="signin()" />
        </div>
        <div class="col-6 pl-default pr-default" ng-show="isSignedIn">
            <input type="submit" class="btn btn-secondary" value="Logout" ng-click="logout()" />
        </div>
        <div class="col-6 pl-default pr-default">
            <input type="submit" class="btn btn-primary" value="Change Password" />
        </div>
    </div>
</div>
vxqlmq5t

vxqlmq5t1#

ng包括:
获取、编译并包含外部html片段。
因此,页面加载后添加的片段和使用js绑定的事件在这些动态添加的元素上不起作用。要解决此问题,可以将这些事件绑定到 onload 参数,它是加载新分部时要计算的表达式。或者您可以尝试将事件附加到javascript中的动态元素

gtlvzcf8

gtlvzcf82#

使用以下命令:

<div ng-include src="'../Content/Shared/Header.html'"></div>
rslzwgfq

rslzwgfq3#

请删除单个报价。

<div ng-include="../Content/Shared/Header.html"></div>
olhwl3o2

olhwl3o24#

这似乎是一个标签关闭问题。
您需要关闭header.html末尾的标记

相关问题