Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (47.6k points)

Currently, I have an Angular.js page that allows searching and displays the results. User clicks on a search result, then clicks the back button. I want the search results to be displayed again but I can't work out how to trigger the search to execute. Here are the details:

  • My Angular.js page is a search page, with a search field and a search button. The user can manually type in a query and press a button and ajax query is fired and the results are displayed. I update the URL with the search term. That all works fine.

  • User clicks on a result of the search and is taken to a different page - that works fine too.

  • User clicks the back button and goes back to my angular search page, and the correct URL is displayed, including the search term. All works fine.

  • I have bound the search field value to the search term in the URL, so it contains the expected search term. All works fine.

How do I get the search function to execute again without the user having to press the "Search'' button ``? If it was jquery then I would execute a function in the document ready function. I can't see the Angular.js equivalent.

1 Answer

0 votes
by (106k points)

To execute AngularJS controller function on page table you can just get away with private inner function see the example below:-

var init = function () { 

// check if there is a query in url 

// and fire search in case its value is not empty 


// and fire it after definition 


Related questions

Browse Categories