1

The UI Router manages states for AngularJS applications and supports nested views as well as multiple named views for the same state. Multiple named views are used like this:

<body>
  <div ui-view="viewA"></div>
  <div ui-view="viewB"></div>
</body>

You can also pass URL-parameters into states when navigating between states via ui-sref (Check this question: Angular ui-router - how to access parameters in nested, named view, passed from the parent template?).

Q: Is it possible to pass parameters to a named view using ui-view which then is propagated to the according state?

Q: How do i pass parameters if i switch between states by using $state.go(newState)?

A: $state.go(newState, { Param: 123 });

Community
  • 1
  • 1
H W
  • 2,556
  • 3
  • 21
  • 45
  • 5
    you can probably use $state.go(newState, { Param: 123 }) – gaurav5430 Feb 16 '16 at 11:59
  • ok, that works - i hoped i could modify the newState string, since i am relying on a 3rd Party lib which only takes a state as parameter :/ – H W Feb 16 '16 at 12:01
  • Where is the connection to my question, Michael Hobbs? Your link explains services and has nothing to do with routing. – H W Feb 16 '16 at 12:36

1 Answers1

0

The $state.go(newState, { Param: 123 }) suggested in the comments is definitely valid.

I tried using another method and it worked as well.In the main app.js file where I have defined my states, I defined a variable var myData={}; outside the module definition(but in the JS file) . Think of this as a global data variable of sorts.

In the controller for viewA you can set a variable by setting

myData.somevalue=$scope.valueFromViewA;

You can access this value in viewB by something like

$scope.valueInB=myData.somevalue

As I said, this is one way of doing it, services is another and the methods in the comment are valid too.

Satej S
  • 2,113
  • 1
  • 16
  • 22
  • Well you created an object which is available in all scopes. You can also use a service to share this between different controllers and have a testable angular-component :) My intention was to use multiple named views and initialize them with the same state (just different input parameters). – H W Feb 16 '16 at 14:05