无法在forEach.after读取null的属性'insertBefore' [英] Cannot read property 'insertBefore' of null at forEach.after
问题描述
我有一个非常简单的html页面,使用 ng-include
加载两个不同的html文件: -
< body ng-controller =testCtrl>
< div class =panel panel-primary>
< h3 class =panel-heading>测试< / h3>
< ng-include src ='View / Details.html'ng-show =details/>
< ng-include src ='View / Summary.html'ng-show =summary/>
< / div>
< / body>
最初只有详细信息
变量为真它正在加载详细信息
视图,如下所示: -
< div class =panel-body>
< table class =table table-striped table-bordered>
< thead>
< tr>
< th> Id< / th>
< th>名称< / th>
< / tr>
< / thead>
< tbody>
< tr ng-repeat =项目中的项目>
< td> {{item.id}}< / td>
< td> {{item.name}}< / td>
< / tr>
< / tbody>
< / table>
< / div>
以下是供参考的控制器: -
.controller(testCtrl,function($ scope){
$ scope.loadItems = function(){
$ scope.items = [
{id:1,name:dummy},
{id:2,name:dummy1},
{id:3,name:dummy2}
] ;
}
$ scope.loadItems();
}
当我加载页面时,它正在正确显示数据,但没有事件被触发(所有按钮点击处理程序通过 ng-click
&与控制器中定义的行为相关联),所以我继续前进,并检查控制台,它显示以下错误:
$ b
TypeError:无法读取null的属性'insertBefore'
at forEach.after(myUrl)
Object.JQLite。(匿名函数)[as after]
我我对Angular很新颖。我看到了很少的线程,并试图操纵我的标记代码,但没有运气。
< ng-include /> - 应该是< ng-include>< / ng-include>
。另外ng-if通常比ng-show更好,因为它减少了结果html的数量。
休息作品: plnkr.co/edit / EmUYuHltWaXnjEC6juid?p =预览。
I have a very simple html page where I am loading two different html files using ng-include
:-
<body ng-controller="testCtrl">
<div class="panel panel-primary">
<h3 class="panel-heading">Test</h3>
<ng-include src="'View/Details.html'" ng-show="details" />
<ng-include src="'View/Summary.html'" ng-show="summary" />
</div>
</body>
Initially only the details
variable is true thus it is loading Details
view which looks like this:-
<div class="panel-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
</tr>
</tbody>
</table>
</div>
and here is the controller for reference:-
.controller("testCtrl", function ($scope) {
$scope.loadItems = function () {
$scope.items= [
{ id: 1, name: "dummy" },
{ id: 2, name: "dummy1" },
{ id: 3, name: "dummy2" }
];
}
$scope.loadItems();
}
When I load the page it is displaying the data properly but no events are getting triggered (all button click handlers are attached via ng-click
& associated with behaviors defined in controller) so I went ahead and checked the console, it is displaying the following error:-
TypeError: Cannot read property 'insertBefore' of null at forEach.after (myUrl) at Object.JQLite.(anonymous function) [as after]
I am pretty new to Angular. I saw few threads and tried to manipulate my mark-up code but no luck.
You cant <ng-include/>
-- should be <ng-include></ng-include>
. Also ng-if is usually better than ng-show, since it reduces amount of result html.
Rest works: plnkr.co/edit/EmUYuHltWaXnjEC6juid?p=preview.
这篇关于无法在forEach.after读取null的属性'insertBefore'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!