loading-controller.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { Injectable } from '@angular/core';
  2. import { App } from '../app/app';
  3. import { Config } from '../../config/config';
  4. import { Loading } from './loading';
  5. /**
  6. * @name LoadingController
  7. * @description
  8. * An overlay that can be used to indicate activity while blocking user
  9. * interaction. The loading indicator appears on top of the app's content,
  10. * and can be dismissed by the app to resume user interaction with
  11. * the app. It includes an optional backdrop, which can be disabled
  12. * by setting `showBackdrop: false` upon creation.
  13. *
  14. * ### Creating
  15. * You can pass all of the loading options in the first argument of
  16. * the create method: `create(opts)`. The spinner name should be
  17. * passed in the `spinner` property, and any optional HTML can be passed
  18. * in the `content` property. If you do not pass a value to `spinner`
  19. * the loading indicator will use the spinner specified by the mode. To
  20. * set the spinner name across the app, set the value of `loadingSpinner`
  21. * in your app's config. To hide the spinner, set `loadingSpinner: 'hide'`
  22. * in the app's config or pass `spinner: 'hide'` in the loading
  23. * options. See the [create](#create) method below for all available options.
  24. *
  25. * ### Dismissing
  26. * The loading indicator can be dismissed automatically after a specific
  27. * amount of time by passing the number of milliseconds to display it in
  28. * the `duration` of the loading options. By default the loading indicator
  29. * will show even during page changes, but this can be disabled by setting
  30. * `dismissOnPageChange` to `true`. To dismiss the loading indicator after
  31. * creation, call the `dismiss()` method on the Loading instance. The
  32. * `onDidDismiss` function can be called to perform an action after the loading
  33. * indicator is dismissed.
  34. *
  35. * >Note that after the component is dismissed, it will not be usable anymore
  36. * and another one must be created. This can be avoided by wrapping the
  37. * creation and presentation of the component in a reusable function as shown
  38. * in the `usage` section below.
  39. *
  40. * ### Limitations
  41. * The element is styled to appear on top of other content by setting its
  42. * `z-index` property. You must ensure no element has a stacking context with
  43. * a higher `z-index` than this element.
  44. *
  45. * @usage
  46. * ```ts
  47. * import { LoadingController } from 'ionic-angular';
  48. *
  49. * constructor(public loadingCtrl: LoadingController) { }
  50. *
  51. * presentLoadingDefault() {
  52. * const loading = this.loadingCtrl.create({
  53. * content: 'Please wait...'
  54. * });
  55. *
  56. * loading.present();
  57. *
  58. * setTimeout(() => {
  59. * loading.dismiss();
  60. * }, 5000);
  61. * }
  62. *
  63. * presentLoadingCustom() {
  64. * const loading = this.loadingCtrl.create({
  65. * spinner: 'hide',
  66. * content: `
  67. * <div class="custom-spinner-container">
  68. * <div class="custom-spinner-box"></div>
  69. * </div>`,
  70. * duration: 5000
  71. * });
  72. *
  73. * loading.onDidDismiss(() => {
  74. * console.log('Dismissed loading');
  75. * });
  76. *
  77. * loading.present();
  78. * }
  79. *
  80. * presentLoadingText() {
  81. * const loading = this.loadingCtrl.create({
  82. * spinner: 'hide',
  83. * content: 'Loading Please Wait...'
  84. * });
  85. *
  86. * loading.present();
  87. *
  88. * setTimeout(() => {
  89. * this.nav.push(Page2);
  90. * }, 1000);
  91. *
  92. * setTimeout(() => {
  93. * loading.dismiss();
  94. * }, 5000);
  95. * }
  96. * ```
  97. * @advanced
  98. *
  99. * Loading options
  100. *
  101. * | Option | Type | Description |
  102. * |-----------------------|------------|------------------------------------------------------------------------------------------------------------------|
  103. * | spinner |`string` | The name of the SVG spinner for the loading indicator. |
  104. * | content |`string` | The html content for the loading indicator. |
  105. * | cssClass |`string` | Additional classes for custom styles, separated by spaces. |
  106. * | showBackdrop |`boolean` | Whether to show the backdrop. Default true. |
  107. * | enableBackdropDismiss | `boolean` | Whether the loading indicator should be dismissed by tapping the backdrop. Default false. |
  108. * | dismissOnPageChange |`boolean` | Whether to dismiss the indicator when navigating to a new page. Default false. |
  109. * | duration |`number` | How many milliseconds to wait before hiding the indicator. By default, it will show until `dismiss()` is called. |
  110. *
  111. * @demo /docs/demos/src/loading/
  112. * @see {@link /docs/api/components/spinner/Spinner Spinner API Docs}
  113. */
  114. export class LoadingController {
  115. constructor(_app, config) {
  116. this._app = _app;
  117. this.config = config;
  118. }
  119. /**
  120. * Create a loading indicator. See below for options.
  121. * @param {LoadingOptions} [opts] Loading options
  122. * @returns {Loading} Returns a Loading Instance
  123. */
  124. create(opts = {}) {
  125. return new Loading(this._app, opts, this.config);
  126. }
  127. }
  128. LoadingController.decorators = [
  129. { type: Injectable },
  130. ];
  131. /** @nocollapse */
  132. LoadingController.ctorParameters = () => [
  133. { type: App, },
  134. { type: Config, },
  135. ];
  136. //# sourceMappingURL=loading-controller.js.map