访问ng-template内的元素 [英] Accessing elements inside ng-template

查看:147
本文介绍了访问ng-template内的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/ng-template" id="popupTemplate">                                             
<div id="myPopup">                   
            <input type="checkbox" name="backup"/><label for="backup">Backup</label>
</div>
</script>

我想从外部脚本访问弹出div,以动态添加更多复选框.我尝试使用jQuery $("#myPopup"),但未访问元素.有什么办法可以做到这一点?

I want to access the popup div from outside script for adding more check boxes dynamically. I tried using jQuery $("#myPopup") but it is not accessing the element. Is there any way to achieve this?

推荐答案

<script type="text/ng-template"></script>中编写的模板将以给定的ID存储在$templateCache中.
使用-$templateCache.get('popupTemplate')
在控制器中检索模板 更新它.
使用-$templateCache.put('popupTemplate', '__updatedContent__')

The template written inside <script type="text/ng-template"></script> will be stored in $templateCache with the given id.
Retrieve the template in your controller using -- $templateCache.get('popupTemplate')
Update it.
Add it back to the $templateCache using -- $templateCache.put('popupTemplate', '__updatedContent__')

这篇关于访问ng-template内的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆