2016-11-30 93 views
0

更新的對象我的$範圍值沒有得到,而無需使用location.reload沒有更新

嗨,我會得到API對象在那裏我有更新一個值的列表,在更新模式彈出該值後,我如果不使用location.reload,我無法獲得新的更新值。有沒有其他解決方案,我使用兩個不同的控制器。

Will get list of objects from this 
$scope.groups=response.data 

將NG-重複此組在那裏,我的編輯按鈕,每一行,一旦我點擊編輯按鈕,彈出窗口將打開

$scope.editGroup = function(u) { 
    $scope.groupName=u.groupName; 
    $scope.groupId=u.groupId; 
    ModalService.showModal({ 
     templateUrl: 'app/components/modal/editGroupDetails.html', 
     controller: "ModalController", 
     scope: $scope 
    }).then(function(modal) { 
     modal.element.modal(); 
     modal.close.then(function(result) { 

      $scope.message = "You said " + result; 
     }); 
    }); 
}; 

下一次我編輯的組名,我會點擊提交

$scope.updateGroupName=function(){ 
       var data={ 
       "groupId": $scope.groupId, 
       "groupName": $scope.groupName 
     } 
     url=globalUrlConfig.globalAdminApi+globalUrlConfig.updateGroup+$scope.schoolId; 
     $http({ 
      method: 'PUT', 
      url: url, 
      data: data, 
     }).success(function(response) { 
      console.log(response) 
      if(response._statusCode==200){ 
       alert(response.data); 

       location.reload(); 
      } 
      else{ 
       alert("not updated") 
      } 

     }) 
    } 

不使用location.reload我不能夠顯示更新的數據

+1

您必須更新視圖中顯示的對象本身。 – Ladmerc

+0

嘗試通過使用唯一值(如id,索引 –

回答

0

使用$rootscope這樣

添加此$rootScope.$emit("refreshData", {}); 而不是Location.reload();

然後在您的負載數據,主控制器添加此無刷新

var RefreshValue = $rootScope.$on("refreshData", function() { 
      GetValueMethod(); // call your method (List of object) for get data without reload form 
     }); 
     $scope.$on('$destroy', RefreshValue); 

不要忘記注入$rootScope

+0

)來更改您已在$ scope.groups中更新的值感謝很多@Roshan其工作出色 –