AngulaJS路由 ui-router 传递多个参数

时间:2023-03-10 08:31:26
AngulaJS路由 ui-router 传递多个参数

定义路由
.state(‘txnresult’, { 
url: ‘/txnresult/:originAmount/:finalAmount/:currentPoint/:txnId/:discountAmount’, 
templateUrl: ‘templates/txnresult.html’, 
controller: ‘TxnResultCtrl’ 
})

基本参数: 
‘/user/:id’ 
‘/user/{id}’ 
‘/user/{id:int}’

使用正则表达式: 
‘/user/{id:[0-9]{1,8}’ 
//匹配所有以user开始的url 并将剩余参数传给id 
‘/user/{id:.*}’ 
‘/user/*id

传递参数方式1
href=”#/txnresult/{{originAmount}}/{{finalAmount}}/{{currentPoint}}/{{txnId}}/{{discountAmount}}”

传递参数方式2
$state.Go(‘txnresult’,{originAmount: d.result.originAmount,finalAmount: d.result.finalAmount,currentPoint: d.result.currentPoint,txnId: d.result.txnId,discountAmount: d.result.discountAmount});

获取参数
$scope.originAmount = $stateParams.originAmount; 
$scope.finalAmount = $stateParams.finalAmount; 
$scope.currentPoint = $stateParams.currentPoint; 
$scope.discountAmount = $stateParams.discountAmount; 
$scope.txnId = $stateParams.txnId;