问题描述
<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内的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!