Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ionic load action


May 22, 2021 ionic


Table of contents


ionic load action

$ionicLoading is a load interaction by ionic default. The contents can also be modified inside the template.

Usage

angular.module('LoadingApp', ['ionic'])
.controller('LoadingCtrl', function($scope, $ionicLoading) {
  $scope.show = function() {
    $ionicLoading.show({
      template: 'Loading...'
    });
  };
  $scope.hide = function(){
    $ionicLoading.hide();
  };
});

Method

Displays a load effect.

show(opts)
Parameters Type Details
opts object

The option of the loading indicator. Available properties:

  • {string=} the template indicator.
  • {string=} templateUrl with html templates as an indicator.
  • {boolean=} the noBackdrop It appears by default.
  • {number=} delay delayed by the delay of the delay of the indicator. The default is no delay.
  • {number=} duration waiting for a few milliseconds. By default, the indicator is displayed until .hide()

Hide a load effect.

hide()

Api

Property Type Details
delegate-handle
(Optional)
字符串

The handle defines a $ionicListDelegate of .

show-delete
(Optional)
布尔值

The delete button for the list item is currently displayed or hidden.

show-reorder
(Optional)
布尔值

The sort button for list items is currently displayed or hidden.

can-swipe
(Optional)
布尔值

Whether the list item is allowed to slide the Display Options button. Default: true.


HTML code:

<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    
    <title>Ionic Modal</title>

     <link href="//www.w3cschool.cn/statics/demosource/ionic.min.css" rel="stylesheet">
    <script src="//www.w3cschool.cn/statics/demosource/ionic.bundle.min.js"></script>
  </head>
  <body ng-controller="AppCtrl">
    
      <ion-view title="Home">
        <ion-header-bar>
          <h1 class="title">The Stooges</h1>
        </ion-header-bar>
        <ion-content has-header="true">
          <ion-list>
            <ion-item ng-repeat="stooge in stooges" href="#">{{stooge.name}}</ion-item>
          </ion-list>
        </ion-content>
      </ion-view>
    
  </body>
</html>

JavaScript code

angular.module('ionicApp', ['ionic'])
.controller('AppCtrl', function($scope, $timeout, $ionicLoading) {

  // Setup the loader
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  });
  
  // Set a timeout to clear loader, however you would actually call the $ionicLoading.hide(); method whenever everything is ready or loaded.
  $timeout(function () {
    $ionicLoading.hide();
    $scope.stooges = [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}];
  }, 2000);
  
});

Try it out . . .


$ionicLoadingConfig

Set the default option for loading:

Usage:

var app = angular.module('myApp', ['ionic'])
app.constant('$ionicLoadingConfig', {
  template: '默认加载模板……'
});
app.controller('AppCtrl', function($scope, $ionicLoading) {
  $scope.showLoading = function() {
    $ionicLoading.show(); //配置选项在 $ionicLoadingConfig 设置
  };
});