2016-11-30 95 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其工作出色 –