AngularJS类型错误:无法读取空的财产“的insertBefore” [英] AngularJS TypeError: Cannot read property 'insertBefore' of null

查看:1832
本文介绍了AngularJS类型错误:无法读取空的财产“的insertBefore”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法总结我的脑海围绕我做错了这里。我想从一个php文件拉JSON数据,然后显示在我的角度应用程序。

我的app.js:

  VAR应用= angular.module(MyApp的,[]);app.controller(ClientHealthCtrl功能($范围,$ HTTP){
    $ http.get('json.php')。
        成功(功能(数据,状态,头,配置){
            $ scope.rows =数据;
    })。
    错误(功能(数据,状态,头,配置){
        //记录错误
    });
});

我的HTML:

 <体类=皮肤黑NG-应用=MyApp的>
...
< TBODY NG控制器=ClientHealthCtrl>
  < TR类=link_backNG重复=计算机行>
    &所述; TD>&下; A HREF =#CID = {{Computer.id}}> {{Computer.ComputerName}}&下; / A>&下; / TD>
    < TD>< I类=发FA-FW发检查方的风格=COLOR:#008000;>< / I> {{Computer.WmiTest}}< / TD>
    < TD>< I类=发FA-FW发检查方的风格=COLOR:#008000;>< / I> {{Computer.SmsClientService}}< / TD>
    < TD>< I类=发FA-FW发检查方的风格=COLOR:#008000;>< / I> {{Computer.McAfeeFrameworkService}}< / TD>
    < TD>< I类=发FA-FW发检查方的风格=COLOR:#008000;>< / I> {{Computer.RemoteManagement}}< / TD>
  < / TR>
< / TBODY>

从而导致...

 类型错误:无法读取属性'的insertBefore'空的
    在https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2067:13
    在的forEach(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:113:18)
    在fo​​rEach.after(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2066:5)
    在Object.JQLite(匿名函数)作为后(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2104:17)
    在https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13294:22
    在https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:3745:29
    在对象<&匿名GT; (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13293:13)
    在Object.Scope。$摘要(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7693:38)
    在Object.Scope。$应用(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7894:24)
    在完成(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:8883:20)
    在此输入code


解决方案

尝试包裹< TR> ...< / TR> 内的元素< D​​IV> ...< / DIV>

综观角源$ C ​​$ C,它是抱怨一些节点没有父节点。

其实,我发现你的问题寻找解决同样的错误在我的code时。
这是我做什么,和它的工作。

I can't seem to wrap my mind around what I am doing wrong here. I am trying to pull json data from a php file and then display it in my Angular app.

My app.js:

var app = angular.module("MyApp", []);

app.controller("ClientHealthCtrl", function($scope, $http) {
    $http.get('json.php').
        success(function(data, status, headers, config) {
            $scope.rows = data;
    }).
    error(function(data, status, headers, config) {
        // log error
    });
});

My HTML:

<body class="skin-black" ng-app="MyApp">
...
<tbody ng-controller="ClientHealthCtrl">
  <tr class="link_back" ng-repeat="Computer in rows">
    <td><a href="#cid={{Computer.id}}">{{Computer.ComputerName}}</a></td>
    <td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.WmiTest}}</td>
    <td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.SmsClientService}}</td>
    <td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.McAfeeFrameworkService}}</td>
    <td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.RemoteManagement}}</td>
  </tr>
</tbody>

Which results in...

TypeError: Cannot read property 'insertBefore' of null
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2067:13
    at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:113:18)
    at forEach.after (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2066:5)
    at Object.JQLite.(anonymous function) [as after] (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2104:17)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13294:22
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:3745:29
    at Object.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13293:13)
    at Object.Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7693:38)
    at Object.Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7894:24)
    at done (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:8883:20) 
    enter code here

解决方案

Try wrapping the <tr>...</tr> element inside a <div>...</div>.

Looking at the source code of Angular, it is complaining some node has no parent node.

Actually, I found out your question when looking to fix the same error in my code. It's what I did, and it worked.

这篇关于AngularJS类型错误:无法读取空的财产“的insertBefore”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆