[英]Accessing and refreshing AngularJS ng-repeat inside ng-repeat
[英]Angularjs ng-repeat is not refreshing with updated values
我具有在弹出窗口(ngdialog)上插入和更新记录的功能。 当Im在数据库中插入和更新记录时,正在添加和更新记录,但是使用ng-repeat不会绑定那些更新的值。
仅当我刷新整个页面时,才会显示更新的记录。
控制器代码:
$scope.OpenUserPlaceMap = function (userplace) {
if (angular.isObject(userplace)) {
$scope.UserPlaceID = userplace.Id;
$scope.UserPlaceName = userplace.Name;
$scope.FormattedAddress = userplace.FormattedAddress;
}
else {
$scope.UserPlaceID = '';
$scope.UserPlaceName = '';
$scope.FormattedAddress = '';
}
ngDialogAlert.ShowPopup('UserPlacesMap.html', 'CommanCtrl', $scope);
};
$scope.SubmitUserPlace = function (flg) {
$scope.error = [];
var UserPlace = {
"Id": $scope.UserPlaceID,
"UserId": $scope.UserId,
"Name": $scope.UserPlaceName,
"FormattedAddress": $scope.FormattedAddress,
"CircleID": $scope.DefaultCircle,
"Latitude": $scope.Latitude,
"Logitude": $scope.Logitude,
"Flag": flg
};
SWT360Service.InUpdDelUserPlace(UserPlace).success(function (data) {
if (data > 0) {
ngDialogAlert.ClosePopup();
$scope.error.push('Saved Successfully');
ngDialogAlert.ShowAlert(true, $scope.error);
$scope.LoadUserPlaces();
}
else {
$scope.error.push('User Place not saved Successfully !');
}
}).error(function (data) {
$scope.error.push(data);
});
}
$scope.LoadUserPlaces = function () {
$scope.UserPlaces = '';
SWT360Service.GetUserPlace(null, $scope.UserId, $scope.DefaultCircle).success(function (data) {
$scope.UserPlaces = data;
});
};
视图:
<div class="container" ng-repeat="place in UserPlaces" style="cursor:pointer;" ng-click="OpenUserPlaceMap(place);">
<div class="col-lg-12 bg-success text-center">
<i class="fa fa-map-marker"></i> <span style="display:none;">{{place.id}}</span> <span>{{place.Name}}</span> <br />
<span>{{place.FormattedAddress}}</span><br>
</div>
<div class="clearfix"></div>
<hr>
</div>
尝试在如下所示的UserPlaces
上添加观察者, UserPlaces
所有内容包装起来。 $ watch监视并更新范围。
$scope.OpenUserPlaceMap = function (userplace) {
if (angular.isObject(userplace)) {
$scope.UserPlaceID = userplace.Id;
$scope.UserPlaceName = userplace.Name;
$scope.FormattedAddress = userplace.FormattedAddress;
}
else {
$scope.UserPlaceID = '';
$scope.UserPlaceName = '';
$scope.FormattedAddress = '';
}
ngDialogAlert.ShowPopup('UserPlacesMap.html', 'CommanCtrl', $scope);
};
$scope.$watch('UserPlaces', function(UserPlaces) {
$scope.SubmitUserPlace = function (flg) {
$scope.error = [];
var UserPlace = {
"Id": $scope.UserPlaceID,
"UserId": $scope.UserId,
"Name": $scope.UserPlaceName,
"FormattedAddress": $scope.FormattedAddress,
"CircleID": $scope.DefaultCircle,
"Latitude": $scope.Latitude,
"Logitude": $scope.Logitude,
"Flag": flg
};
SWT360Service.InUpdDelUserPlace(UserPlace).success(function (data) {
if (data > 0) {
ngDialogAlert.ClosePopup();
$scope.error.push('Saved Successfully');
ngDialogAlert.ShowAlert(true, $scope.error);
$scope.LoadUserPlaces();
} else {
$scope.error.push('User Place not saved Successfully !');
}
}).error(function (data) {
$scope.error.push(data);
});
}
$scope.LoadUserPlaces = function () {
$scope.UserPlaces = '';
SWT360Service.GetUserPlace(null, $scope.UserId, $scope.DefaultCircle).success(function (data) {
$scope.UserPlaces = data;
});
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.