jwa*_*nga 11 javascript angularjs
以下小提琴呈现3列递增数字,表示具有不同模板的指令:一个内联,一个预加载,一个来自外部模板.当您选择"添加"按钮时,列会递增.表示带有外部模板的指令的列似乎在add按钮将新项目推送到现有数组时创建一个新数组,然后抛出以下错误:
TypeError:无法调用null的方法'insertBefore'
有什么想法发生了什么?
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'
}
});
Run Code Online (Sandbox Code Playgroud)
我已经通过将指令包装在父元素中并将ng-repeat移动到父元素来解决了这个问题.任何有关为什么会产生影响的见解仍然会受到赞赏.
http://jsfiddle.net/jwanga/EaRHD/13/
<li ng-repeat="item in items"><item-3 data="item"></item-3></li>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3842 次 |
最近记录: |