Angularjs动作后刷新同一页面

Angularjs动作后刷新同一页面,angularjs,Angularjs,我正在尝试在点击链接时加载一个函数,这非常有效。然后angularjs发挥它的魔力,直到它到达显示用户反馈的点。我需要在删除项目后刷新页面,但它根本不会刷新 以下是我的href: <a ng-click="deleteGroup(group.id)" target="_self"> <img src="img/deleteGroupIcon.png" width="45px"/></a> 和我的html: <div class="searchResul

我正在尝试在点击链接时加载一个函数,这非常有效。然后angularjs发挥它的魔力,直到它到达显示用户反馈的点。我需要在删除项目后刷新页面,但它根本不会刷新

以下是我的href:

<a ng-click="deleteGroup(group.id)" target="_self">
<img src="img/deleteGroupIcon.png" width="45px"/></a>
和我的html:

<div class="searchResults" ng-repeat="group in groups | searchForUser:searchString">
<div class="manageGroupWrapper">
    <a class="normal" href="#">
        <div class="newName h3">
            {{group.title}}
        </div>
        <div class="newProfile">
            <img ng-src="{{group.image}}" width="200px"/>
        </div>
        <div class="imageWrapper">
            <a ui-sref="add_group" class="editGroupIcon"><img src="img/editGroupIcon.png" width="50px"/></a>
            <a ng-click="deleteGroup(group.id)" target="_self"><img src="img/deleteGroupIcon.png" width="45px"/></a>
        </div>
    </a>
</div>

您的$scope.deleteGroup函数应将其目标组从$scope.groups中删除,以便自动更新ng repeat的内容,不再显示该组

$scope.deleteGroup = function (group) {
    $http({
        method: 'POST',
        url: apiUrl + 'group/delete',
        data: {'groupId': group.$groupId},  // pass in data as strings
        //headers: {'Content-Type': 'application/x-www-form-urlencoded'}  
        // set the headers so angular passing info as 
        // form data (not request payload)
    }).success(function(data) {
        $scope.groups.splice($scope.groups.indexOf(group));
    });
};

要使用uiRouter强制刷新页面,可以使用
$state.go(target,params,{reload:true})


为什么要刷新页面?你能给我们更多的HTML源代码吗?因为,如果您使用的是
ng repeat
,您只需将刚刚删除的组从您要重复的数组中删除,就可以避免以这种方式刷新页面。AngularJS将处理数据绑定并从视图中删除组。(这由ng repeat处理)您使用的是角度路由还是普通网页(URL中是否有#符号)?是否显示警报?通常情况下,您不应该在Angular应用程序中重新加载页面,只需更新模型。如何在
$timeout
.ui路由器中成功包装删除。是的,会显示警报,如果页面未刷新,则在我按F5之前不会删除产品。我正在使用ng repeat,是否需要额外的步骤?因为现在它直到F5才删除产品
$scope.deleteGroup = function (group) {
    $http({
        method: 'POST',
        url: apiUrl + 'group/delete',
        data: {'groupId': group.$groupId},  // pass in data as strings
        //headers: {'Content-Type': 'application/x-www-form-urlencoded'}  
        // set the headers so angular passing info as 
        // form data (not request payload)
    }).success(function(data) {
        $scope.groups.splice($scope.groups.indexOf(group));
    });
};
$scope.deleteGroup = function (group) {
  $http({
    method: 'POST',
    url: apiUrl + 'group/delete',
    data: {'groupId': group.groupId},  // pass in data as strings
    //headers: {'Content-Type': 'application/x-www-form-urlencoded'}  
    // set the headers so angular passing info as 
    // form data (not request payload)
  }).success(function(data) {
    // This will reload the current state with the same stateParams
    $state.go($state.current.name, $stateParams, {reload: true});
  });
};