0

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);
});
dyaa
  • 1,440
  • 18
  • 43
TechQuery
  • 253
  • 3
  • 17

1 Answers1

0

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

Brent Washburne
  • 12,904
  • 4
  • 60
  • 82
  • Thanks Brent. But the problem here is update is present in a different controller and my employee scope is in different page. I m not sure on how to directly assign the response from this controller to the view of another page. My another question is, in my code, i m redirecting it to the list page where it is supposed to execute the query but why the redirect is not happening as expected and url also not changing to #/Emplist and obviously the query to updated list is not executed as well – TechQuery May 19 '15 at 17:09
  • It sounds like you don't have your app structured correctly. When a page is loaded (from a redirect or clicked link), it loads the controller for that page and updates the $scope. You shouldn't be passing things between controllers. The best you can do is to pass query strings in the URL and interpret them in the next controller. – Brent Washburne May 19 '15 at 17:14
  • My main List page is EmpList and from there its redirected to EmpDetail page where i have update button . When i click the update , controller in EmpDetail is triggered and its redirected to EmpList. Since i have the view available in EmpList, i m not sure how i can populate using $scope in the controller of empDetail:( – TechQuery May 19 '15 at 17:17
  • This is a different question. You need to focus on one specific problem in a question so an answer can be provided. Create a new question so people can comment and answer. – Brent Washburne May 19 '15 at 17:21