Simply add the tdLoading
attribute with a [name] value to the element you want to mask.
Dont forget to add the asterisk syntax before the tdLoading
directive if its not used in a <ng-template>
element. More ingo on the asterisk (*) syntax here
This service is designed to be a factory of loading masks and serves as a facade for their usage.
Simply add this service as a provider to be able to use it in a component.
TdLoadingService.create() method receives as parameter an object that implements the [ITdLoadingConfig] interface.
interface ITdLoadingConfig { name: string; type?: LoadingType; mode?: LoadingMode; color?: 'primary' | 'accent' | 'warn'; }
Import the [CovalentLoadingModule] in your NgModule:
import { CovalentLoadingModule } from '@covalent/core/loading'; @NgModule({ imports: [ CovalentLoadingModule, ... ], ... }) export class MyModule {}
Example for (*) syntax:
<div *tdLoading="'stringName'; type:'circular'; mode:'indeterminate'; strategy:'replace'; color:'primary'"> ... </div>
import { TdLoadingService } from '@covalent/core/loading'; ... }) export class Demo { constructor(private _loadingService: TdLoadingService) { ... } registerLoading(): void { this._loadingService.register('stringName'); } resolveLoading(): void { this._loadingService.resolve('stringName'); } }
Exmaple for (*) until async syntax:
<div *tdLoading="let item until observable | async; type:'circular'; color:'primary'"> {{item}} </div>
Example for <ng-template>
syntax:
<ng-template tdLoading="stringName" tdLoadingType="circular" tdLoadingMode="indeterminate" tdLoadingStrategy="replace" tdLoadingColor="primary"> ... </ng-template>
import { TdLoadingService } from '@covalent/core/loading'; ... }) export class Demo { constructor(private _loadingService: TdLoadingService) { ... } registerLoading(): void { this._loadingService.register('stringName'); } resolveLoading(): void { this._loadingService.resolve('stringName'); } }
Example for <ng-template>
until syntax:
<ng-template tdLoading [tdLoadingUntil]="boolean"> ... </ng-template>
Example creating a global mask with the tdLoadingService
:
import { TdLoadingService, LoadingType, LoadingMode } from '@covalent/core/loading'; ... export class Demo { constructor(private _loadingService: TdLoadingService) { this._loadingService.create({ name: 'stringName', type: LoadingType.Circular, mode: LoadingMode.Indeterminate, color: 'accent', }); } registerLoading(): void { this._loadingService.register('stringName'); } resolveLoading(): void { this._loadingService.resolve('stringName'); // or this._loadingService.resolveAll('stringName'); } }