Before some time I have written a blog post about routing - Routing with UI-Router and Angular.js I have got few questions from my reader in email. One of question is to how we can activate state of UI-Router as UI-Router works with state instead of URLs. In this blog post we are going to explain, different ways to activate state in UI-Router.
There are three ways of activating state in UI-Router.
It is a one of convenient method of changing state, Returns a promise representing the state of transition. It calls underlying $State.Transition method internally but automatically sets option location: true , inheritance:true, relative: $state.$current and notify:true. This allows you to set easily update parameters with passing arguments. You can find more information about that at following location.
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options
We have used this method already in previous example. It is a directive that bind a link to state. If the state has an associated URL, the directive automatically generate and update the href attribute via $State.href() method. Clicking on link will trigger a state transition with parameters.
You can use it in following way.
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
As we have seen in previous blog post, most of the state will have URL associated with it. Now when user access the index.html/contactus, it will activate contactus state and load the template associated with this state. You can also pass the parameters with that. Following is documentation for the same.
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
Hope you like it, Stay tuned for more!!.
There are three ways of activating state in UI-Router.
- Call $State.go
- UI-sref directive as link
- Navigate to URL associated with State
Call $State.Go:
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options
UI-sref directive as link:
You can use it in following way.
ui-sref='stateName'
- Navigate to state, no params.'stateName'
can be any valid absolute or relative state, following the same syntax rules as$state.go()
ui-sref='stateName({param: value, param: value})'
- Navigate to state, with params.
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
Navigate to the URL associated with State:
https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
Hope you like it, Stay tuned for more!!.
0 comments:
Post a Comment
Your feedback is very important to me. Please provide your feedback via putting comments.