Angularjs 为什么ng repeate对象没有得到更新?
这是从服务器加载列表的功能。最初会显示列表,但当应用筛选器时获得空响应时,它仍会显示以前的结果,而不会清除以前的列表Angularjs 为什么ng repeate对象没有得到更新?,angularjs,angularjs-scope,angularjs-ng-repeat,Angularjs,Angularjs Scope,Angularjs Ng Repeat,这是从服务器加载列表的功能。最初会显示列表,但当应用筛选器时获得空响应时,它仍会显示以前的结果,而不会清除以前的列表 $scope.browseListing = function (strURL) { $scope.CurrentTab = strURL; $scope.getURL(strURL); $http.post($scope.URL) .then(function (response) {
$scope.browseListing = function (strURL) {
$scope.CurrentTab = strURL;
$scope.getURL(strURL);
$http.post($scope.URL)
.then(function (response) {
if (response.data != 'null') {
$scope.Data = response.data;
$scope.TotalListingCount = $scope.Data.length;
$window.alert('Result is not null');
}
else {
$scope.TotalListingCount = '0';
$window.alert('Result is null');
$scope.Data = [];
}
}, function (response) {
$log.info(response);
});
};
已编辑
如何解决此问题,以便在响应为空时清除以前的列表,并且不显示任何列表?可能是您的范围没有更新。请尝试以下方法(这不是100%的好方法,但此时您可以解决您的问题)
- 请检查您的控制台是否有任何错误
以下命令创建新作用域并继承原型:
ng repeat
,ng include
,ng开关
,ng视图
,ng控制器
,指令
带作用域:true
,指令
带转录lude:true
因此,使用$parent
和'ng-repeate'来引用父作用域,而不是使用新创建的作用域-
将ng中的$parent
添加到UI
中的scope属性后,它会根据更改更新UI
更新从中检索到的相应html标记和json数据server@Aravind,我是否需要根据响应显示/隐藏ng repeate?没有数据时是否会收到“结果为空”警报?是的,返回空响应时会弹出警报。@jmd不完全取决于您正在寻找的解决方案。如果存在一些HTML,我们至少可以尝试找到问题所在。控制台中出现错误,错误:$rootScope:inprog操作已在进行中
删除缓存。@Ramesh Rajendran,我也尝试了$范围$$phase
。添加$$phase
后,控制台中没有错误,但问题仍然存在。当您获取空数据时,能否向我显示您的响应JSON?@RameshRajendran,我有一个带有空响应的更新问题。
if(!$scope.$$phase) {
$scope.$apply(
$scope.Data = [];
);
}
$scope.TotalListingCount = '0';
$window.alert('Result is null');
.then(function (response) {
$scope.TotalListingCount = '0';
$scope.Data = [];
if (response.data != 'null') {
$scope.Data = response.data;
$scope.TotalListingCount = $scope.Data.length;
$window.alert('Result is not null');
}
else {
$window.alert('Result is null');
}
}