javascript - 利用angularjs在html中嵌入html
PHP中文网
PHP中文网 2017-04-10 13:12:47
[JavaScript讨论组]

我有一个html文件a.html,如下:

a.html

我想利用angularjs在a.html嵌入另外一个b.html,如下:

b.html

希望的结果如下:

a.html

b.html

请问如何实现?

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(5)
迷茫
<p>
  a.html
  <bhtml></bhtml>
</p>
angular
    .module('app')
    .directive('bhtml',function(){
        return {
            templateUrl:'/b.html',
            restrict:'E',
            replace:true
        }
    })

这个差不多可以做到lz想要的效果了。但是比较麻烦一点,简单点的办法会多一个标签:

<p>
  a.html
  <p ng-include="/b.html"></p>
</p>

结果:

<p>
  a.html
  <p ng-include="/b.html">
    <p>
        b.html
    </p>
  </p>
</p>
迷茫

ng-include..

伊谢尔伦

set transclued: true in your directive, and put transclude in your directive template where you want to embed another html template

PHPz

a.html

<p>
    hello a
    <dv ng-include="b.html"></p>
</p>

b.html

<p>
    hello b
</p>
PHP中文网

ui-router

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号