首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在angular的ng-switch中使用html模板

在angular的ng-switch中使用html模板
EN

Stack Overflow用户
提问于 2013-11-20 19:45:25
回答 3查看 13.1K关注 0票数 12

我正在制作一个随着用户点击而移动的“交互式菜单”。我想知道是否有一种方法可以在ng-switch中包含html模板,因为每个“switch”中的所有逻辑都是不同的-它将导致巨大的html文件。

代码语言:javascript
复制
<div class="content" ng-switch on="selection">
 <div ng-switch-when="1" >
   <h1>1</h1>
 </div>
 <div ng-switch-when="2">
   <h1>2</h1>       
 </div>
</div>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-11-20 19:48:46

使用ngInclude

代码语言:javascript
复制
<div class="content" ng-switch on="selection">
    <div ng-switch-when="1" >
        <ng-include src="'template1.html'"></ng-include>
    </div>
    <div ng-switch-when="2">
        <ng-include src="'template2.html'"></ng-include>
    </div>
</div>

注意:如果您正在对路径进行硬编码,请不要忘记在双引号中使用单引号。

票数 19
EN

Stack Overflow用户

发布于 2013-11-20 19:49:51

您应该能够使用ng-include指令来完成此操作:

代码语言:javascript
复制
<div class="content" ng-switch on="selection">
    <ng-switch-when="1" ng-include="//TEMPLATE PATH">
    <ng-switch-when="2" ng-include="//TEMPLATE 2 PATH">
</div> 
票数 11
EN

Stack Overflow用户

发布于 2015-03-30 17:25:48

代码语言:javascript
复制
   **I used ng-Include this way.**

    <!-- Main content -->
    <div class="row">

      <!-- right col -->
      <section class="col-lg-12">
        <ul class="nav nav-tabs responsive ui-tabbed" id="myTab">
          <li class="active">
            <a  data-ng-click=' main.active.tab = "tab-1" '>Tab 1</a>
          </li>

    </ul>
    <!-- end responsive tabs -->

    <div class="tab-content ui-tabbed-contents responsive">
    <div data-ng-switch = " main.active.tab ">
      <div data-ng-switch-when='tab-1' >
        <ng-include src="'tab-one.html'" ></ng-include>
      </div>

    </div>

    </div>


    </div>
    <!-- end main tabs container -->
    </section>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20095032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档