数据已成功从DB中删除但未刷新AngularJS中的当前页面

时间:2015-06-30 17:19:56

标签: javascript angularjs asp.net-web-api

我多次尝试删除数据并成功删除数据但未显示已更新的学生完整列表.....

手动刷新网页后,它会显示更新的学生列表,请帮帮我。

  
X.controller('StudentController', ['$scope', 'Student', 'Department', '$routeParams','$location', function ($scope, Student, Department, $routeParams,$location) {
    $scope.v = 'test value';
    
    $scope.profileid = $routeParams.Id;
    console.log($scope.profileid);
        ////////////////RETRIVE ALL DATA FROM DB///////////////
    function init() {
        /////RETRIVE DATA FOR STUDENT/////////
   
        $scope.student = { Name: '', Phone: '', Class_id: '', Department_id: '' };
        $scope.students = [];
        Student.get(function (response) {
            console.log("List of Student");
            $scope.students = response.Data;
            console.log($scope.students);

        });

        ///////RETRIVE DATA FOR DEPARTMENT////////////////////
        $scope.depts = [];
        Department.get(function (response) {
            console.log("List of Dept");
            $scope.depts = response.DeptData;
            console.log($scope.depts);
        });

    };
////////////RETRIVE SPECIFIC DATA INTO DB/////////////
Student.get({ Id: $scope.profileid }, function (response) {
        console.log("SPECIFIC DATA");
        $scope.student = response.Data;
        console.log($scope.students);

    });
/////////////////////////////DELETE//////////////////
    $scope.Stddelete = function (profileId) {
        Student.delete({ Id: profileId });
        console.log("DELETE");
        init();
    };

    init();



    }
]);

1 个答案:

答案 0 :(得分:1)

要更新DOM,您需要splice数组中的对象。

$scope.students.splice($index,1);

示例:

$scope.Stddelete = function (profileId,index) {
        Student.delete({ Id: profileId });
        $scope.students.splice(index,1);
        console.log("DELETE");
        init();
    };