我试图在加载 View 时显示模式。
代码:
//View
<div id="showCom" ng-controller="showmodalCtrl" ng-init="init()">
<div class="modal fade" id="companyModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Please Select Company</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label class="control-label">Recipient:</label>
<input type="text" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
//Controller
.controller('showmodalCtrl', ['$scope', function($scope){
$scope.init = function(){
$('#companyModal').modal("show");
}
}])
一切正常,模式已显示,但我在控制台上收到此错误:
Type error : Cannot read property 'childNodes' of undefined
我不知道为什么会发生这种情况。 另外,如果我从模态中删除“表单”,我不会收到任何错误。所以我猜问题出在表单上,但我无法解决它。
提前致谢。
最佳答案
我遇到了同样的问题,我设法通过将模式打开函数包装在 $timeout() 或普通的 setTimeout() 函数中来解决它。
setTimeout(function(){
jQuery('#messageModal').modal('show');
}, 0);
关于angularjs - 类型错误 : Cannot read property 'childNodes' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27776174/