问题
<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