AngularJS $ routeParams VS $ stateParamsrouteParams、AngularJS、stateParams、VS

2023-09-13 04:36:51 作者:精神病人思路广

之间有什么区别:

$routeParams and $stateParams

和什么时候使用什么?

推荐答案

两者都是从不同的路由器模块。您可以在应用程序中使用的任何人。

Both are from different router modules. You can use anyone in your application.

如果您使用 ngRoute 模块,那么你应该使用 $ routeParams ( https://docs.angularjs.org/api/ngRoute )。这是由角团队提供。它只有一个 NG-视图。你不能做嵌套视图功能。

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.

如果您使用 UI路由器模块,那么你应该使用 $ stateParams ( https://github.com/angular-ui/ui-router )。这是从贡献模块。它有更多的功能数量比较比 ngRoute 。它支持嵌套视图的概念。可以指定多个用户界面视图

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

查看更多:http://www.amasik.com/angularjs-ngroute-vs-ui-router/