angularjs - 类型错误 : Cannot read property 'childNodes' of undefined

标签 angularjs twitter-bootstrap

我试图在加载 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">&times;</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/

相关文章:

javascript - Angular.js 仅在前端或后端处理数据

javascript - 将 NODE_ENV 传递给 Angular

html - 按钮的 Bootstrap 选项卡?

angularjs - 当 Modal 中有大量项目时,angular-ui-select 下拉列表的行为缓慢

angularjs - 我应该使用 typescript 吗?或者我可以只使用 ES6?

angularjs - 我们可以将 TypeScript 迁移到 Google AtScript 吗?

html - 模态框在导航栏选项卡内不起作用( Bootstrap )

javascript - jQuery 验证插件、Bootstrap、Jasny Bootstrap 文件输入正则表达式 - 验证在 Firefox 中工作而不是在 Chrome/IE 中

javascript - 在不依赖 jquery 的情况下一起使用 bootstrap 和 angularjs 的合理方法

javascript - 单击 Codeigniter 中的“编辑”按钮时更新 Bootstrap 表