Accessing elements inside ng-template

北城以北 提交于 2019-12-11 13:18:07

问题


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

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?


回答1:


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__')



来源:https://stackoverflow.com/questions/28712122/accessing-elements-inside-ng-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!