What is the difference between:
$routeParams and $stateParams
and when to use what?
$stateParams captures url-based params that $state considers applies to that state, even if its child state contains more params. $state. params seems to capture all url + non-url based params of the current state you are in. If you are in state parent.
A ui-sref is a directive, and behaves similar to an html href . Instead of referencing a url like an href , it references a state. The ui-sref directive automatically builds a href attribute for you ( <a href=...> </a> ) based on your state's url.
UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).
Both are from different router modules. You can use anyone in your application.
If you use ngRoute
module, then you should use $routeParams
( https://docs.angularjs.org/api/ngRoute ) . This is provided by Angular team. It has only one ng-view
. you can not do nested views functionality.
If you use ui-router
module, then you should use $stateParams
( https://github.com/angular-ui/ui-router ). This is from contributed module. It has number of additional functionality compare than ngRoute
. It supports nested view concepts. you can specify multiple ui-view
See more: http://www.amasik.com/angularjs-ngroute-vs-ui-router/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With