I've recently started working with Angular and I'm facing some confusion with routes. I am using Asp.Net MVC in my project. I have a method in my Angular controller that I only want to run when the page loads for the first time after being redirected from the Home Page. Is there a way to achieve this? I thought I had it all figured out, but the method is running on every postback, whereas I need it to run only once when the page opens initially. The method in question is:
getSearch();
function getSearch() {
generalsearchService.getSearch()
.success(function (data) {
$scope.gridOptions.data = data.SearchResults;
});
};
The reason I use the above method is to call an ActionResult in my MVC controller via an Angular Service. This was done as a workaround to resolve a previous issue mentioned in this Stack Overflow thread. While the workaround seemed to work fine, it caused issues when trying to perform a "normal" search by clicking the Search button. This action sends the request back to the MVC Controller to execute the search based on user-selected parameters. However, having the getSearch() code above hinders the SubmitSearch functionality.
Below is the complete code of my Angular controller:
And here's my MVC Controller Code:
Your assistance in resolving this matter would be greatly appreciated!