Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS $routeParams vs $stateParams

What is the difference between:

$routeParams and $stateParams

and when to use what?

like image 414
David Dury Avatar asked Nov 15 '14 14:11

David Dury


People also ask

What is $stateParams in AngularJS?

$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.

What does UI sref do?

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.

What is UI router?

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).


1 Answers

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/

like image 199
Asik Avatar answered Oct 18 '22 05:10

Asik