ionic 页面加载事件及loading动画

页面加载完成事件(非刷新情况下,页面切换是不会重复触发此事件的,只在第一次进入页面时触发,需要重复触发的话请使用 $ionicView.enter 事件)

angular.module('app.controllers', [])
.controller('page6Ctrl', ['$scope', '$http', '$stateParams', '$ionicLoading',
    // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
    // You can include any angular dependencies as parameters for this function
    // TIP: Access Route Parameters for your page via $stateParams.parameterName
    function($scope, $http, $stateParams, $ionicLoading) {
        $scope.$on('$ionicView.loaded', function(event, data) {
            $ionicLoading.show();

            $http.get("js/123.json")
                .success(function(res) {
                    $ionicLoading.hide();
                });
        });
    }
])

其他事件如下:

$ionicView.loadedThe view has loaded. This event only happens once per view being created and added to the DOM. If a view leaves but is cached, then this event will not fire again on a subsequent viewing. The loaded event is good place to put your setup code for the view; however, it is not the recommended event to listen to when a view becomes active.
$ionicView.enterThe view has fully entered and is now the active view. This event will fire, whether it was the first load or a cached view.
$ionicView.leaveThe view has finished leaving and is no longer the active view. This event will fire, whether it is cached or destroyed.
$ionicView.beforeEnterThe view is about to enter and become the active view.
$ionicView.beforeLeaveThe view is about to leave and no longer be the active view.
$ionicView.afterEnterThe view has fully entered and is now the active view.
$ionicView.afterLeaveThe view has finished leaving and is no longer the active view.
$ionicView.unloadedThe view's controller has been destroyed and its element has been removed from the DOM.
$ionicParentView.enterThe parent view has fully entered and is now the active view. This event will fire, whether it was the first load or a cached view.
$ionicParentView.leaveThe parent view has finished leaving and is no longer the active view. This event will fire, whether it is cached or destroyed.
$ionicParentView.beforeEnterThe parent view is about to enter and become the active view.
$ionicParentView.beforeLeaveThe parent view is about to leave and no longer be the active view.
$ionicParentView.afterEnterThe parent view has fully entered and is now the active view.
$ionicParentView.afterLeaveThe parent view has finished leaving and is no longer the active view.

 

官方文档:http://ionicframework.com/docs/api/directive/ionView/

 

关于$http和$ionicLoading对象,要在控制器使用ionic系统对象的时候,只需要在第二参数里加入变量,然后在最后的函数参数里也加入参数就可以了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值