我有一个页面应用程序,其中'网页'正在使用ng-switch进行切换。在第二页我有一个模式,我使用这种功能,打开它:Angular getElementById()在switch语句中返回null
var modal = document.getElementById('myModal');
vm.openModal = function(src) {
modal.style.display = 'block';
modalImg.src = src;
};
modal.onclick = function() {
modal.style.display = 'none';
};
而且我的html:
<div ng-switch="vm.step.name">
<div ng-switch-when="prepare">
Some content of first page
</div>
<div ng-switch-when="action">
Some content of second page
<button ng-click="vm.openModal('bootHP.jpg')">Open modal</button>
<!-- The Modal -->
<div id="myModal" class="modal-instruction absolute block">
<img class="modal-content-guide centered" id="img01">
</div>
</div>
</div>
的问题是,我得到VAR模式=零,所以对于某种原因它没有在开关中看到id ='myModal'。有人能帮助我澄清为什么这样表现,我该如何解决这个问题?
感谢您的回答!
尝试angular.element($ document).find('myModal');你需要注入$ document ofc。 – rrd