2015-11-03 143 views
0

我有一個功能來插入和更新彈出(ngdialog)上的記錄。當我添加和更新記錄在數據庫中插入和更新時,但這些更新值不是使用ng-repeat綁定的。Angularjs 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> 

回答

0

嘗試增加對UserPlaces觀察者像下面和包裹裏面的一切。 $觀看手錶並更新範圍。

$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; 
     }); 
    }; 
}); 
+0

阿南德感謝答覆。 Im獲取Userplaces對象中的更新記錄,但ng-repeat在綁定後不刷新。 –