【发布时间】:2014-08-08 09:46:13
【问题描述】:
我正在尝试设置复杂的 URL 结构:
http://example.com/quote/:param1/:param2/:param3/:param4
每个州都使用相同的模板,除了 1。
我的问题是,有没有办法在没有多个模板的情况下将每个参数动态传递到下一个状态?还是我需要设置单独的模板并只更改 ui-sref
这是我的状态:
.state('quote', {
url: '/quote',
...
})
.state('quote.policy', {
url: '/',
templateUrl: 'partials/quote/quote.select.html',
page: {next: 'location'}
...
})
.state('quote.location', {
url: '/:policy',
templateUrl: 'partials/quote/quote.select.html',
page: {next: 'age'}
...
})
.state('quote.age', {
url: '/:policy/:state',
templateUrl: 'partials/quote/quote.select.html',
page: {next: 'income'}
...
})
.state('quote.income', {
url: '/:policy/:state/:age',
templateUrl: 'partials/quote/quote.income-select.html',
page: {next: 'priority'}
...
})
.state('quote.priority', {
url: '/:policy/:state/:age/:income',
templateUrl: 'partials/quote/quote.select.html',
...
})
每个参数都带有一个子引用状态。他们都使用相同的模板:
snippet from partials/quote/quote.select.html
<label
ng-repeat="option in options[page.type]"
ui-sref="quote.{{page.next}}({ page.type : option.value })"
ng-click="formData.selections[page.type] = option.value">
我遇到的另一个问题是当前的 ui-sref 没有将值传递给 URL,即没有附加新值。
【问题讨论】:
-
各州不应该是彼此的孩子吗? IE。
quote.income应该是quote.policy.location.age.income? -
啊...这是一个非常有效的观点!抱歉,我是 Angular 的新手,所以还在学习。当我在自己的代码中解决它时,我会用解决方案更新问题。
标签: javascript angularjs angular-ui-router