$location.path() Method Not Reloading New Data In ASP.NET MVC Web API With AngularJS
Hello,
I was trying to integrate AngularJS into a simple ASP.NET MVC Web API application with Save functionality. Basically, when you have finished posting data the next logic will be to redirect the user to the display all page. However, I stumbled into an issue in which the $location service does not reload data.
According to the docs,the $location service allows you to change only the URL; it does not allow you to reload the page. So after placing breakpoints in the Api Controller, I noticed that the GetAll() method is called first next is the Save() method. The solution to this dilemma is to transfer the $location.path() method inside the success function so that the Save() method in the Api Controller is executed first.
Code With Issue: $location.path() is outside the success function.
Fix: $location.path() is inside the success function.
Cheers! :-)
I was trying to integrate AngularJS into a simple ASP.NET MVC Web API application with Save functionality. Basically, when you have finished posting data the next logic will be to redirect the user to the display all page. However, I stumbled into an issue in which the $location service does not reload data.
According to the docs,the $location service allows you to change only the URL; it does not allow you to reload the page. So after placing breakpoints in the Api Controller, I noticed that the GetAll() method is called first next is the Save() method. The solution to this dilemma is to transfer the $location.path() method inside the success function so that the Save() method in the Api Controller is executed first.
Code With Issue: $location.path() is outside the success function.
$scope.Add = function () { $http({ method: "POST", data: $scope.employee, url: "/api/employees" }) .then(function (response) { $scope.employees = response.data; $scope.employee = { "FirstName": "", "LastName": "", "Age": "", "Salary": "" }; }); $location.path('/allemployees'); }
$scope.Add = function () { $http({ method: "POST", data: $scope.employee, url: "/api/employees" }) .then(function (response) { $scope.employees = response.data; $scope.employee = { "FirstName": "", "LastName": "", "Age": "", "Salary": "" }; $location.path('/allemployees'); }); }
Cheers! :-)
Comments
Post a Comment