在我的Ionic應用程序中,我想將參數從一個子視圖傳遞到另一個子視圖。當我第一次傳遞參數時,它按照我的預期工作,但是我的問題是,當我返回第一個子視圖,然後轉到另一個子視圖時,它會轉到那個沒有參數的頁面。angular.js ui-router pass no data
的index.html(項目/ WWW)
<!DOCTYPE html>
<html>
<head>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script src="js/main.js"></script>
<script src="js/routes.js"></script>
</head>
<body ng-app="app" animation="slide-left-right-ios7" >
<!-- main window -->
<div>
<ion-nav-view></ion-nav-view>
</div>
</body>
</html>
route.js(WWW/JS/route.js)
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('mainUser', { // first window
url: '/mainuser',
templateUrl: 'templates/mainUser.html',
controller: 'mainCtrl'
})
.state('userDrive', { // second window
url: '/user_drive',
params: {
driveData: null // parameter send
},
templateUrl: 'templates/user_drive.html',
controller: 'DriveCtrl'
});
$urlRouterProvider.otherwise('/mainUser');
});
模板:下面我的代碼給出/mainUser.html
<ion-side-menus>
<ion-side-menu-content>
<ion-content class="padding" style="background-color:#fff;">
<input type="date" ng-model="selectData.selectedDate" placeholder="Date">
<input type="time" ng-model="selectData.selectedTime" placeholder="Time">
</ion-content>
<div class="bar bar-footer">
<div class="button-bar">
<a ui-sref="userDrive({ driveData: selectData })" class="button"> Drive </a>
</div>
</div>
</ion-side-menu-content>
</ion-side-menus>
這裏點擊Drive
按鈕後,它會正確地重定向到userDrive
子視圖,參數爲driveData
。但是,我回到mainUser
,然後更改selectData.selectedDate
和selectData.selectedTime
,然後再次點擊Drive
按鈕,它將重定向到userDrive
子視圖而沒有driveData
參數。
userDrive控制器
.controller('DriveCtrl', function($scope, $state, $stateParams) {
console.log("DriveCtrl"); // after redirect to this controller second time
// it also print no value
// seems might be DriveCtrl is not called
console.log("$stateParams : ", $stateParams);
})
你不應該刪除緩存,你應該使用視圖生命週期。 –
但爲什麼我們不應該刪除緩存?你能告訴更多嗎? – sabbir