Angular JS CRUD update not refreshing

让人想犯罪 __ 提交于 2020-01-25 07:35:12

问题


My view is not getting reflected after the update/Delete/Create

My List page is EmpList. My update page is EmpDetail.

Here is my controller

   $scope.UpdateEmp = function () {
            var empl=$scope.Employee;
            empFactory.empUpdate.update({ EmpID: $routeParams.EmpID, empval: empl });
            $location.path('/EmpList');

        };

Here is my Service

 var resource = {
        empUpdate:
            $resource('../../Employee/PutEmployee/:EmpID', { EmpID: '@EmpID', empval: '@empl' }, { update: { method: 'PUT', isArray: true } })
    }

    return resource;

Here is my MVC controller

 [HttpPut]
        public JsonResult PutEmployee(int id, Employee empval)
        {
            empval.EmpID = id;
            int index = emp.GetEmployees().FindIndex(i => i.EmpID == empval.EmpID);
            emp.GetEmployees().RemoveAt(index);
            emp.GetEmployees().Add(empval);
            return Json(emp.GetEmployees(), JsonRequestBehavior.AllowGet);
        }

MVC controller is getting called and the data is getting updated correctly, but it's not getting reflected in the main page

Note: In Emplist.html, I have the controller mapped where I m doing the query part to reflect the changes. The URL is not redirected to EmpList at all.

$scope.Employees = empFactories.query(function () {
    console.log($scope.Employees);
});

回答1:


You're sending the data but not using the reply:

reply = empFactory.empUpdate.update({ EmpID: $routeParams.EmpID, empval: empl });

Now you can assign the reply to your $scope



来源:https://stackoverflow.com/questions/30331609/angular-js-crud-update-not-refreshing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!