在寫iOS Native App時早已知道視圖生命週期 (View Life Cycle)非常重要,因為它會決定我們接下來時做的流程。現在使用Ionic同樣也有視圖生命週期 (Ionic View Life Cycle),現在就稍微來瞭解其前後關係吧!
實作的部分跟iOS同樣是寫在Controller中。
$scope.$on(
'$ionicView.loaded'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.enter'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.leave'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.beforeEnter'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.afterEnter'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.beforeLeave'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.afterLeave'
,
function
(){
// Anything you can think of
});
$scope.$on(
'$ionicView.unloaded'
,
function
(){
// Anything you can think of
});
FIRST TIME VIEW INITIALIZATION
- View 1 – loaded
- View 1 – beforeEnter
- View 1 – enter
- View 1 – afterEnter
TRANSITION FROM ONE VIEW TO ANOTHER
- View 2 – loaded
- View 2 – beforeEnter
- View 1 – beforeLeave
- View 2 – enter
- View 1 – leave
- View 2 – afterEnter
- View 1 – afterLeave
名稱不太一樣,然而原理差不多,所以只要多寫幾次,就熟能生巧。
隨意留個言吧:)~