首页 > 解决方案 > angularj js:html模板插入:每次插入修改属性值

问题描述

你好堆栈溢出社区!这是我的代码的迷你版。在这个例子中,我试图在 index.html 的每个 div 中插入我的模板,并在每次插入时更改它的 id。+ 为什么 h1 元素会消失?

    <div id= "simpleSearchType OR advancedSearchType OR expertSearchType"  >
    this is the div to be inserted
</div >

任何帮助将不胜感激,谢谢。

标签: htmlangularjstemplatesinsertattributes

解决方案


一个更简单的方法是使用ng-if指令。

您可以searchType在控制器中设置变量,并通过将 div 挂接到ng-if.


推荐阅读