我有这个州定义:
.state("workPlan.list", {
url: "MainPage",
templateUrl: "app/workPlan/templates/workPlanList.tmpl.html",
controller: "workPlanListController",
controllerAs: "list",
resolve: {
workPlans: ["workPlanServise", workPlanServiseResolver],
inspectionAuthority: ["lookupService", inspectionAuthorityResolver],
clients: ["lookupService", ClientsResolver]
}
})
目前的路径是:
/cities#/MainPage
我需要传递一些数据:
'Table':'Clients'
'Key':'Name'
'Value':'ClientId'
'Table':'Dates'
'Key':'Desc'
'Value':'DateId'
'Table':'Sites'
'Key':'SiteName'
'Value':'SiteId'
我需要在URL路径中发送上面的数据:
/cities#/MainPage?{'Table':'Clients','Key':'Name','Value':'ClientId'}{...}{...}
然后在状态定义中我需要在解析函数中使用它。
所以我的问题是可以以上面的格式发送路径中的数据,如何在解析函数中访问它。
答案 0 :(得分:2)
当然你可以做到,一切都在文档中:ui-router github wiki
您将使用参数(双冒号 - 例如“:table”)定义您的状态网址,并在$stateParams
函数中使用resolve
服务:
$stateProvider
.state('contacts.detail', {
url: "/MainPage/:table/:key/:value",
templateUrl: "app/workPlan/templates/workPlanList.tmpl.html",
controller: "workPlanListController",
controllerAs: "list",
resolve: {
data: ['$stateParams', function($stateParams) {
console.log($stateParams.table);
}]
}
})
如果您注入$stateParams
服务,那么参数也将在状态控制器中可用。
答案 1 :(得分:2)
呼叫你的州
$state.go('stateName', {test_one: 'para1',test_two: para2, test_three:'para3'});
或
window.location.href =
this.$state.href('stateName',
{test_one: 'para1',test_two: para2, test_three:'para3'});
您定义州的routes.js。
$stateProvider
.state({
name: 'stateName',
url: '/test/?test_one&test_two&test_three',
views: {
'content@portal-layout': {
controller: Controller,
template: require('./test.html')
},
}
})
最后你的网址看起来像这样
https://test/?test_one=para1&test_two=para2&test_three=para3