以下代码展示了三列递增数字,分别使用不同的模板渲染指令:一个是内联模板,一个是预加载模板,还有一个来自外部模板。当您选择“添加”按钮时,这些列会递增。似乎当具有外部模板指令的列通过“添加”按钮将新项目推到现有数组中时,就会创建一个新数组,并抛出以下错误:
TypeError: Cannot call method 'insertBefore' of null
您有什么想法? http://jsfiddle.net/jwanga/EaRHD/
TypeError: Cannot call method 'insertBefore' of null
您有什么想法? http://jsfiddle.net/jwanga/EaRHD/
angular.module('app',[]).controller('controller', function($scope){
$scope.items = [1,2,3,4,5,6,7,8,9];
$scope.add = function(){
$scope.items.push($scope.items[$scope.items.length - 1]+1);
}
}).directive('item1', function(){
return{
restrict:'E',
replace:true,
scope: {
data: '=data'
},
template:'<li>{{data}}</li>'
}
}).directive('item2', function(){
return{
restrict:'E',
replace:true,
scope: {
data: '=data'
},
templateUrl:'item.html'
}
}).directive('item3', function(){
return{
restrict:'E',
replace:true,
scope: {
data: '=data'
},
templateUrl:'https://s3.amazonaws.com/thedigitalself-public/jsfiddle-EaRHD-template.html'
}
});