UNPKG

5.26 kBMarkdownView Raw
1# tdLoading
2
3Simply add the `tdLoading` attribute with a [name] value to the element you want to mask.
4
5Dont 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](https://angular.io/guide/structural-directives#asterisk)
6
7## API Summary
8
9#### Inputs
10
11- tdLoading: string
12 - Name reference of the loading mask, used to register/resolve requests to the mask.
13- tdLoadingType?: LoadingType or ["linear" | "circular"]
14 - Sets the type of loading mask depending on value.
15 - Defaults to [LoadingType.Circular | "circular"]
16- tdLoadingMode?: LoadingMode or ["determinate" | "indeterminate"]
17 - Sets the mode of loading mask depending on value.
18 - Defaults to [LoadingMode.Indeterminate | "indeterminate"].
19- tdLoadingStrategy?: LoadingStrategy or ["replace" | "overlay"]
20 - Sets the strategy of loading mask depending on value.
21 - Defaults to [LoadingMode.Replace | "replace"]
22- tdLoadingColor?: "primary" | "accent" | "warn"
23 - Sets the theme color of the loading component.
24 - Defaults to "primary"
25- tdLoadingUntil?: any
26 - If its null, undefined or false it will be used to register requests to the mask.
27 - Else if its any value that can be resolved as true, it will resolve the mask.
28 - [name] is optional when using [until], but can still be used to register/resolve it manually.
29
30# tdLoadingService
31
32This service is designed to be a factory of loading masks and serves as a facade for their usage.
33
34Simply add this service as a provider to be able to use it in a component.
35
36TdLoadingService.create() method receives as parameter an object that implements the [ITdLoadingConfig] interface.
37
38```typescript
39interface ITdLoadingConfig {
40 name: string;
41 type?: LoadingType;
42 mode?: LoadingMode;
43 color?: 'primary' | 'accent' | 'warn';
44}
45```
46
47## API Summary
48
49#### Methods
50
51- register: function(name?: string, registers: number = 1)
52 - Registers a request for the loading mask referenced by the name parameter.
53 - Can optionally pass registers argument to set a number of register calls.
54 - If no paramemeters are used, then default main mask will be used
55- resolve: function(name?: string, resolves: number = 1)
56 - Resolves a request for the loading mask referenced by the name parameter.
57 - Can optionally pass resolves argument to set a number of resolve calls.
58 - If no paramemeters are used, then default main mask will be used.
59- resolveAll: function(name?: string)
60 - Resolves all requests for the loading mask referenced by the name parameter.
61 - If no paramemeters are used, then default main mask will be used.
62- setValue: function(name: string, value: number)
63 - Set value on a loading mask referenced by the name parameter.
64 - Usage only available if its mode is 'determinate'.
65- create: function(options: ITdLoadingConfig
66 - Creates a fullscreen loading mask and attaches it to the DOM with the given configuration.
67 - Only displayed when the mask has a request registered on it.
68
69## Setup
70
71Import the [CovalentLoadingModule] in your NgModule:
72
73```typescript
74import { CovalentLoadingModule } from '@covalent/core/loading';
75@NgModule({
76 imports: [
77 CovalentLoadingModule,
78 ...
79 ],
80 ...
81})
82export class MyModule {}
83```
84
85## Usage
86
87Example for (\*) syntax:
88
89```html
90<div
91 *tdLoading="'stringName'; type:'circular'; mode:'indeterminate'; strategy:'replace'; color:'primary'"
92>
93 ...
94</div>
95```
96
97```typescript
98import { TdLoadingService } from '@covalent/core/loading';
99...
100})
101export class Demo {
102 constructor(private _loadingService: TdLoadingService) {
103 ...
104 }
105
106 registerLoading(): void {
107 this._loadingService.register('stringName');
108 }
109
110 resolveLoading(): void {
111 this._loadingService.resolve('stringName');
112 }
113}
114```
115
116Exmaple for (\*) until async syntax:
117
118```html
119<div
120 *tdLoading="let item until observable | async; type:'circular'; color:'primary'"
121>
122 {{item}}
123</div>
124```
125
126Example for `<ng-template>` syntax:
127
128```html
129<ng-template
130 tdLoading="stringName"
131 tdLoadingType="circular"
132 tdLoadingMode="indeterminate"
133 tdLoadingStrategy="replace"
134 tdLoadingColor="primary"
135>
136 ...
137</ng-template>
138```
139
140```typescript
141import { TdLoadingService } from '@covalent/core/loading';
142...
143})
144export class Demo {
145 constructor(private _loadingService: TdLoadingService) {
146 ...
147 }
148
149 registerLoading(): void {
150 this._loadingService.register('stringName');
151 }
152
153 resolveLoading(): void {
154 this._loadingService.resolve('stringName');
155 }
156}
157```
158
159Example for `<ng-template>` until syntax:
160
161```html
162<ng-template tdLoading [tdLoadingUntil]="boolean"> ... </ng-template>
163```
164
165Example creating a global mask with the `tdLoadingService`:
166
167```typescript
168import { TdLoadingService, LoadingType, LoadingMode } from '@covalent/core/loading';
169...
170export class Demo {
171 constructor(private _loadingService: TdLoadingService) {
172 this._loadingService.create({
173 name: 'stringName',
174 type: LoadingType.Circular,
175 mode: LoadingMode.Indeterminate,
176 color: 'accent',
177 });
178 }
179
180 registerLoading(): void {
181 this._loadingService.register('stringName');
182 }
183
184 resolveLoading(): void {
185 this._loadingService.resolve('stringName'); // or this._loadingService.resolveAll('stringName');
186 }
187}
188```