一、传递一个单个字段:
在上级页面跳转到下级页面的方法里面,使用from属性:
$state.go('func', {
module: 'getCash',
func: 'index',
from: 3
});
在下级页面的controller中,接收from传递过来的参数:
$scope.page = $state.params.from
二、传递一个对象,有多个字段:
在上级页面跳转到下级页面的方法里面,仍然使用from属性:
$scope.cashBank = {
bankList: $scope.bankList,
currentBank: $scope.currentBank,
treasure:$scope.treasure,
cashNum: 1 //Math.floor(Math.random()*3) 用户已提现的次数 随机数0,1,2 Math.floor是向下取整
}
console.log('提现次数wrwr',$scope.cashBank.cashNum);
console.log('wrwr的财富信息',angular.toJson($scope.cashBank));
$scope.getBankInfo = function(){
$state.go('func', {
module: 'getCash',
func: 'index',
from: angular.toJson($scope.cashBank)
});
}
这里需要传递给下级页面的参数是一个对象cashBank, 这时候在from的属性值中,需要使用angular.toJson包裹一层,将其转化为JSON字符串。
然后,在下级页面的controller中,接收from传递过来的参数,需要使用angular.fromJson包裹一层,将其转化为JSON对象,方法如下:
if($state.params.from){
$scope.cashBank = angular.fromJson($state.params.from);
$scope.currentBank = $scope.cashBank.currentBank;
$scope.bankList = $scope.cashBank.bankList;
$scope.treasure = $scope.cashBank.treasure;
$scope.cashNum = $scope.cashBank.cashNum;
}