我在ng-click事件中修改了$scope,为什么页面部分被修改的数据没有重新渲染
- {{ obj.text }}
$scope.reset=function(){
var sum=0;
this.thinglist.forEach(function (item,index){
if(!item.isDone){
sum++;
}
})
this.many=sum;
// $scope.$apply();
console.log(this.many);
}
$scope.add=function(ei){
// console.log(this)
this.thinglist.push({
text:this.thing,
isDone:false
});
this.thing="";
// this.many++;
this.reset();
// console.log(this.thinglist);
}
$scope.do=function(index){
// console.log(this);
// this.many=this.many-1;
this.thinglist[index].isDone=!this.thinglist[index].isDone;
this.reset();
// $emit('reset');
// console.log($scope.$digest)
// this.$digest();
// console.log(this.many);
// $scope.$apply;
}
在reset方法里面我设置了修改many的值,每次调用下面的do和add的时候,只有add会重新渲染页面.
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
送你一句话:this != $scope。
=======UPDATE========
尝试修改成这样:
我已经解决了这个问题,悲剧,看了一个老外的一篇博客,通过设置定时器解决了.究其原因,应该是脏值检查的问题.虽然已经触发了脏值检查,但是这里检测不到数据的修改.