当我将stateParams传递给另一个状态时,它们会与状态连接并在我的IONIC App中获得以下结果。
var $currState = $ionicHistory.currentView().stateId;
$scope.consoleLog('$currState: ' + $currState); //$currState: app.stateA_purchaseData=[object Object]_supplierData=[object Object]"
$scope.consoleLog('$stateParams: ' + JSON.stringify($stateParams)); //$stateParams: {}
这是配置
state('app.StateA', {
url: '/test-url',
templateUrl: 'templates/test.html',
controller: 'AppCtrl',
cache: false,
params: {
purchaseData: null,
supplierData: null,
}
})
$state.go('app.StateA', {purchaseData: $scope.purchaseData, supplierData: $scope.supplierData });
答案 0 :(得分:1)
这种情况正在发生,因为在Ionic history
的文档中,有一种方法 getCurrentStateId()
将statename
与params
连接起来。
<强> Check from line no 142 in ionic_history.js in github documentation
强>
function getCurrentStateId() {
var id;
if ($state && $state.current && $state.current.name) {
id = $state.current.name;
if ($state.params) {
for (var key in $state.params) {
if ($state.params.hasOwnProperty(key) && $state.params[key]) {
id += "_" + key + "=" + $state.params[key];
}
}
}
return id;
}
// if something goes wrong make sure its got a unique stateId
return ionic.Utils.nextUid();
}
要获取参数, 尝试,
StateParams()
调用getCurrentStateParams()
function getCurrentStateParams() {
var rtn;
if ($state && $state.params) {
for (var key in $state.params) {
if ($state.params.hasOwnProperty(key)) {
rtn = rtn || {};
rtn[key] = $state.params[key];
}
}
}
return rtn;
}
这实际上会为您返回params对象。