我有一个html文件a.html,如下:
<p>
a.html
</p>
我想利用angularjs在a.html嵌入另外一个b.html,如下:
<p>
b.html
</p>
希望的结果如下:
<p>
a.html
<p>
b.html
</p>
</p>
请问如何实现?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ng-include简单, 但是,要实现复杂结构比较困难ng-transcode灵活,容易实现复杂的HTML结构,但是要单独写directive(指令)代码
'<p ng-transclude></p>'相当于一个插入点, 类似Web组件规范中的插入点概念.当你在模版中的HTML元素上使用
<pane>这个指令的时候,<pane>中的内容可以被插入到ng-transcode定义的位置例如:
另外,如果你不想在指令中拼接模版字符串, 你可以使用
templateUrl替代template细节请参考: http://angular.duapp.com/api/ng.directive:ngTransclude
这个差不多可以做到lz想要的效果了。但是比较麻烦一点,简单点的办法会多一个标签:
结果:
ng-include..
set
transclued: truein your directive, and puttranscludein your directive template where you want to embed another html templatea.html
b.html
ui-router