Angular.js 在 $scope.var 更改后不会刷新中继器,而只会在刷新后刷新
Angular.js doesn't refresh the repeater after $scope.var changes but only after refresh
我认为绑定的 2 种方式是有棱角的:
我可以从表单发布到控制器,如果我刷新页面,我会在页面上看到我的输入:
$scope.loadInput = function () {
$scope.me.getList('api') //Restangular - this part works
.then(function(userinput) {
$scope.Input = $scope.Input.concat(userinput);
// scope.input is being referenced by ng-repeater in the page
// so after here a refresh should be triggered.
},function(response){
/*@alon TODO: better error handling than console.log..*/
console.log('Error with response:', response.status);
});
};
在 html 页面中,ng-repeater
遍历for i in input
数组。 但是除非我刷新页面,否则不会显示表单中的新输入。
我会很高兴得到帮助 - 谢谢!
尝试$scope.$apply
:
$scope.loadInput = function () {
$scope.me.getList('api') //Restangular - this part works
.then(function(userinput) {
$scope.$apply(function(){ //let angular know the changes
$scope.Input = $scope.Input.concat(userinput);
});
},function(response){
/*@alon TODO: better error handling than console.log..*/
console.log('Error with response:', response.status);
});
};
原因是:你的ajax是异步的,它将在下一轮执行,但此时,你已经离开了角循环。角度并不知道这些变化,我们这里要用$scope.$apply
进入角度周期。这种情况与使用像$http
这样的角度服务略有不同,当您使用$http
服务并在.success
内处理响应时,angular 会意识到这些变化。
不起作用。您会注意到第一次单击不会刷新视图。
setTimeout(function(){
$scope.checkboxes = $scope.checkboxes.concat([{"text": "text10", checked:true}]);
},1);
使用$scope.$apply
工作的演示
setTimeout(function(){
$scope.$apply(function(){
$scope.checkboxes = $scope.checkboxes.concat([{"text": "text10", checked:true}]);
});
},1);
相关文章:
- 获取中继器控件ASP.Net中显示的单击项目文本框
- 需要在量角器中找到使用ng中继器的li元素的数量
- 如何在中继器中找到标头控制
- 让ASP.NET中继器设置一个动态名称
- 如何在使用Protractor测试时找到ng中继器的最后一个元素
- 如何在AnglujarJS ng中继器中选择特定元素
- 具有多个值的AngularJS滤波器中继器
- 量角器-如何从中继器而不是元素中获得实际值
- 中继器控件内的 IF 条件
- ng中继器打印结果0;当我运行函数时
- 如何在ng中继器运行中执行功能
- 修改asp.net中继器中的嵌入超链接
- 使用 jquery 动画幻灯片使用角度中继器切换
- .toggle() 适用于 ACF 中继器中的所有内容
- 带有中继器的 AngularJS 指令
- angularJS中继器按键错误
- AngularJS-如何在ng中继器中调用以项值为参数的控制器函数
- AngularJS-你能在一个javascript块中引用一个中继器变量吗
- 如何在javascript中获取放置在中继器内的特定标签的文本
- Angular.js 在 $scope.var 更改后不会刷新中继器,而只会在刷新后刷新