0

In our case, we have a search function in our application which shows the search results after entering a search term. The search results are products in our case. When we click on one of these products we are send to the page with information regarding this product. Now our problem, when we want to go back to the search page we want a method to return to the exact same page as before we left the search page. And not an entirely new search page.

We have divided our HTML in 3 views, which we load with the UIRouter.

enter image description here We need to share data between the header, content and footer. When we show our search results, we want to show the amount of results in the header for example.

In short; we need to share our data between controllers / views. What will be the best solution? We have thought about:
Adding a mainController to the body and using this as a medium to communicate data between controllers.. Store all data in a factory and access this factory direct from all controllers. But will all views be updated directly on data change? (2 way binding?)

However, we didn't get it working yet. What would be the best way to manage this?

2
  • Put your stuff in a service (factory for example) and inject this service to all controllers. Commented Dec 9, 2014 at 12:38
  • Thank you for you comment, this will help us in our search for a solution :) Commented Dec 9, 2014 at 13:29

1 Answer 1

1

As mertins mentioned in his comment, a service would do fine for this purpose.

Inject that service to all relevant controllers and indeed, thanks to 2-way binding all relevant data will be updated properly.

Don't use a controller, that's not what they are meant for!

If you need a code example for the service injection comment and I'll update this answer.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! We are going to try it with services now. If we have any questions we wont hesitate to ask them ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.