1

Using Spring 4 and angularjs, I am developing a web application which has the following functionality:

home.html

  • User inputs product search criteria and submits search

results.html

  • The application displays a list of products (within DIV elements) that meets the criteria as returned from the server.
  • For each product, the user can click a "Select" button, or a "Dismiss" button which removes it from the DOM. The "Select" simply adds the product ID to a Javascript array
  • The user can Submit the selection which posts the array of selected products to the server.
  • Also before submission, the user can click a product and thereby navigate to a product.html page which displays further details.

product.html, home.html and results.html are loaded into an ng-view contained in index.html

All this is pretty standard funtionality and it is working for me OK. However, when the user is viewing the product.html page, I need a link back to results.html page that includes (1) the results of the criteria, and (2) any modifications the user had made such as clicking the Submit or Dismiss buttons. Basically, it should be exactly like as if the user opened product.html in a new browser tab and then closed it to return to the results, but instead it is all happening within a ng-view.

My instinct is that this is basically a typical "cart" with the search results being the cart contents. However, I'm unsure if I am correct with this assumption. Also, I'm unsure how to implement this functionality using Spring and angularjs - should this functionality be managed by Spring, angularjs or both.

I'm not looking for the exact code here, but rather a point in the correct direction as to what approach to use to implement this. Thanks.

John Steed
  • 599
  • 1
  • 12
  • 31

1 Answers1

1

One approach is to sort of use a master controller that holds all the data, load it on the body tag (or a higher level div)and then load the other html pages you mention within a nested div. I've also used the cache service for similar functionality but in hindsight, it seems like overkill.

Mike Feltman
  • 5,160
  • 1
  • 17
  • 38
  • I didn't think about just using visibility. I could have one page with two ng-views. I could initially hide the product ng-view and display the results ng-view. When the user clicks a product, that visibility is reversed. And likewise, it is reversed again when the user returns to the search returns. There might be a better way though but I'm unsure. EDIT: I see you can only have one ng-view per template http://stackoverflow.com/questions/17544558/multiple-ng-view-in-single-template-angular-js – John Steed Apr 28 '16 at 12:26
  • Sometimes the easiest solution is the best answer. :) – Mike Feltman Apr 28 '16 at 12:28