Skip to content Skip to sidebar Skip to footer

AngularJS: Pass Parameter Between Controllers

What i am trying to do: I have a ListView (or rather an accordion) which contains several items (for simplicity lets assume those have a unique id and a name). For each item i want

Solution 1:

You have two real alternatives (that you have identified):

  • Use a service
  • Pass the information as part of a url

Both are technically correct and viable but my preference from a semantic and state point of view would be to use a url.

Since you are supplying a clickable link it makes sense that you are linking to something that is linkable (i.e. an item or state that can be identified by a unique url). If you believe an open accordion item to be more an item of state (as opposed to a page) then you could look into ui-router: https://github.com/angular-ui/ui-router

I'm not sure why you are averse to having item IDs in the url. After all anyone that's interested can see any information in the UI with developer tools. If you don't want database schema information in the UI then there are various methods of ID obfuscation to address this.


Post a Comment for "AngularJS: Pass Parameter Between Controllers"