I am trying to pass parameters to a state in angular.js ui-router like the following:
我试图将参数传递给angular.js ui-router中的状态,如下所示:
.state('details', {
url: '/details/:index',
templateUrl: 'views/details.html'
})
The index is being passed through an ng-repeat index
索引正在通过ng-repeat索引传递
<div ng-repeat="program in programs">
<h2>{{program.name}}</h2>
<p>{{program.description || "No Description"}}</p>
<p><a ui-sref="details({index: $index})">View details »</a></p>
</div>
my question is how in details.html do i read the index passed in the url of the state?
我的问题是如何在details.html中读取在状态网址中传递的索引?
1 个解决方案
#1
11
Inject $stateParams in your controller.
在控制器中注入$ stateParams。
Documentation: https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service
文档:https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service
Example: http://plnkr.co/edit/8p55FoKIFHZFcvleFANe?p=preview
示例:http://plnkr.co/edit/8p55FoKIFHZFcvleFANe?p = preview
#1
11
Inject $stateParams in your controller.
在控制器中注入$ stateParams。
Documentation: https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service
文档:https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service
Example: http://plnkr.co/edit/8p55FoKIFHZFcvleFANe?p=preview
示例:http://plnkr.co/edit/8p55FoKIFHZFcvleFANe?p = preview