Skip to content

Commit 684be37

Browse files
committed
fix(BlockUI): Reset should only targets given instance
1 parent 8cb5762 commit 684be37

8 files changed

+185
-53
lines changed

README.md

+63-29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A Block UI implementation for Angular
77
[![Build Status](https://travis-ci.org/kuuurt13/ng-block-ui.svg?branch=master)](https://travis-ci.org/kuuurt13/ng-block-ui)
88

99
## Installation
10+
1011
Add to your project via [npm](https://www.npmjs.com/package/ng-block-ui)
1112

1213
```bash
@@ -27,7 +28,9 @@ import { BlockUIModule } from 'ng-block-ui';
2728
})
2829
export class AppModule { }
2930
```
31+
3032
## Quick Start
33+
3134
Wrap your main components in your app root template with a `block-ui` component.
3235

3336
Import the `BlockUI` decorator into your component and declare a property with the decorator.
@@ -65,16 +68,19 @@ export class AppComponent {
6568
```
6669
6770
## Settings
71+
6872
Settings can be changed on the module level and component/directive level. Also, in some cases settings can be overwritten via the method level.
6973
7074
### Default Message
75+
7176
A default message can be configured to be shown instead of passing a message each time to the `start` method. The default message will be shown any time blocking is activated.
7277
7378
| Setting | Type | Description |
74-
|-----------|----------|------------------------------------------------|
79+
| --------- | -------- | ---------------------------------------------- |
7580
| `message` | `string` | Custom message to be displayed while blocking. |
7681
7782
#### Module Level
83+
7884
```ts
7985
@NgModule({
8086
imports: [
@@ -88,13 +94,15 @@ export class AppModule { }
8894
```
8995
9096
#### Component Level
97+
9198
```html
9299
<block-ui message="Default Message">
93100
<!-- Markup here -->
94101
</block-ui>
95102
```
96103
97104
#### Method Level
105+
98106
```js
99107
@Component({
100108
...,
@@ -118,15 +126,17 @@ export class Cmp {
118126
```
119127
120128
### Delay Start/Stop
129+
121130
When blocking with fast service calls the block overlay can flicker for a small amount of time.
122131
To prevent this a `delayStart` and a `delayStop` can be configured to prevent this scenario.
123132
124133
| Setting | Type | Description |
125-
|--------------|----------|-------------------------------------------------------------------|
134+
| ------------ | -------- | ----------------------------------------------------------------- |
126135
| `delayStart` | `number` | Waits given amount of milliseconds before starting to block. |
127136
| `delayStop` | `number` | Waits given amount of milliseconds before stopping current block. |
128137
129138
#### Module Level
139+
130140
```ts
131141
@NgModule({
132142
imports: [
@@ -141,27 +151,31 @@ export class AppModule { }
141151
```
142152
143153
#### Component Level
154+
144155
```html
145156
<block-ui [delayStart]="500" [delayStop]="500">
146157
<!-- Your app markup here -->
147158
</block-ui>
148159
```
160+
149161
### Custom Template
162+
150163
If you want to display other markup than the default spinner and message then you can provide a custom template.
151164
Custom templates can be provided as a `Component` or `TemplateRef`. The template will then be used instead of the default template whenever blocking.
152165
153166
| Setting | Type | Description |
154-
|------------|-------------------------------------------|------------------------------------------|
167+
| ---------- | ----------------------------------------- | ---------------------------------------- |
155168
| `template` | <code>Component &#124; TemplateRef</code> | Custom template to be used when blocking |
156169
157170
#### Component Custom Template
171+
158172
Create a component and declare it in your app module.
159173
The component also will need to be added to the `entryComponents` property of the module.
160174
161-
*Example Component:*
175+
_Example Component:_
162176
163-
*Note: When providing a `Component` as a template just add the `{{message}}`
164-
interpolation to your template and it will display your default message or the message passed to the `start` method.*
177+
_Note: When providing a `Component` as a template just add the `{{message}}`
178+
interpolation to your template and it will display your default message or the message passed to the `start` method._
165179
166180
```js
167181
// Template component
@@ -170,14 +184,15 @@ interpolation to your template and it will display your default message or the m
170184
template: `
171185
<div class="block-ui-template">
172186
<img src="logo.png" />
173-
<p>{{message}}</p>
187+
<p>{{ message }}</p>
174188
</div>
175-
`
189+
`,
176190
})
177191
export class BlockTemplateCmp {}
178192
```
179193
180194
##### Module Level
195+
181196
```js
182197
@NgModule({
183198
imports: [
@@ -195,14 +210,15 @@ export class AppModule { }
195210
```
196211
197212
##### Component Level
213+
198214
```js
199215
@Component({
200-
selector: 'app-root',
216+
selector: "app-root",
201217
template: `
202218
<block-ui [template]="blockTemplate">
203219
<!-- Your markup here -->
204220
</block-ui>
205-
`
221+
`,
206222
})
207223
export class AppComponent {
208224
// Declare template component
@@ -211,15 +227,16 @@ export class AppComponent {
211227
```
212228
213229
#### TemplateRef Custom Template
214-
Add a `<ng-template>` with a template reference variable to the view. Then pass the template reference variable to the `blockUI` component using the `[template]` property.
215230
216-
*Note: TemplateRef templates can only be set on a Component level.*
231+
Add a `<ng-template>` with a template reference variable to the view. Then pass the template reference variable to the `blockUI` component using the `[template]` property.
217232
233+
_Note: TemplateRef templates can only be set on a Component level._
218234
219235
##### Component Level
236+
220237
```js
221238
@Component({
222-
selector: 'cmp',
239+
selector: "cmp",
223240
template: `
224241
<ng-template #blockTemplate>
225242
<div class="block-ui-template">
@@ -230,12 +247,13 @@ Add a `<ng-template>` with a template reference variable to the view. Then pass
230247
<block-ui [template]="blockTemplate">
231248
<!-- Your app markup here -->
232249
</block-ui>
233-
`
250+
`,
234251
})
235252
export class Cmp {}
236253
```
237254
238255
## Block UI Directive
256+
239257
Sometimes you want to only apply blocking to a certain element in your app.
240258
The Block UI directive can be added to an element to apply blocking only to that specific element.
241259
@@ -266,59 +284,75 @@ export class AppComponent {
266284
```
267285
268286
### Directive Settings
287+
269288
Angular has a specific syntax for passing properties to structural directives. Properties are passed in `key: value;` pair. To pass settings to a Block UI directive they must be passed as shown below.
270289
271290
```html
272-
<div *blockUI="'instance-name'; message: 'Loading'; template: blockTemplate">
273-
</div>
291+
<div
292+
*blockUI="'instance-name'; message: 'Loading'; template: blockTemplate"
293+
></div>
274294
```
275295
276296
## NgBlockUI Instance
277297
278298
### NgBlockUI Instance Properties
299+
279300
Below highlights all the properties that can be found on a BlockUI instance when a class property is decorated with the `@BlockUI()` decorator.
280301
281-
| Property | Description |
282-
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
283-
| `name` | Name of the targeted instance (defaults to main instance). |
284-
| `isActive` | Indicates if the targeted instance is blocking. |
285-
| `start` | Starts blocking for instance, can be passed an optional message. |
286-
| `stop` | Stops blocking for instance. |
287-
| `reset` | Stops blocking for all currently blocking instances app wide regardless of the `delayStop` option. |
288-
| `update` | Updates current instances blocking message with the passed message. |
289-
| `unsubscribe` | Unsubscribe an instance so it no longer can be blocked. All BlockUI components/directives unsubscribe by default during `onDestroy`. |
302+
| Property | Description |
303+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
304+
| `name` | Name of the targeted instance (defaults to main instance). |
305+
| `isActive` | Indicates if the targeted instance is blocking. |
306+
| `start` | Starts blocking for instance, can be passed an optional message. |
307+
| `stop` | Stops blocking for instance. |
308+
| `reset` | Stops blocking for all targeted instances regardless of the `delayStop` option. |
309+
| `resetGlobal` | Stops blocking app wide for all instances regardless of the `delayStop` option. |
310+
| `update` | Updates current instances blocking message with the passed message. |
311+
| `unsubscribe` | Unsubscribe an instance so it no longer can be blocked. All BlockUI components/directives unsubscribe by default during `onDestroy`. |
290312
291313
### NgBlockUI Instance Settings
314+
292315
Below are all the settings that can be passed as a second argument to the `@BlockUI()` decorator (`@BlockUI(<name>, <settings>)`).
293316
294-
| Property | Description |
295-
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
296-
| `scopeToInstance` | When set to `true` a unique `name` will be given to the blockUI instance which will "scope" it to the parent component instance. |
317+
| Property | Description |
318+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
319+
| `scopeToInstance` | When set to `true` a unique `name` will be given to the blockUI instance which will "scope" it to the parent component instance. |
297320
298321
## BlockUIService
322+
299323
In some cases you may want to have more control over all the instances in you app.
300324
Instead of declaring separate instances with the `@BlockUI()` decorator you can use the `BlockUIService`. This service allows you to easily target multiple instance across your app.
301325
302326
| Method | Parameters | Description |
303-
|---------------|------------------------------------------------------------|------------------------------------------------------------------------------------------|
327+
| ------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
304328
| `isActive` | <code>target: string &#124; string[]</code> | Indicates if the targeted instance(s) is blocking. |
305329
| `start` | <code>target: string &#124; string[], message?: any</code> | Starts blocking for a single instance or multiple instances by passing instance name(s). |
306330
| `stop` | <code>target: string &#124; string[]</code> | Stops blocking for a single instance or multiple instances by passing instance name(s). |
307331
| `update` | <code>target: string &#124; string[], message: any</code> | Updates message for a single instance or multiple instances by passing instance name(s). |
308332
| `reset` | <code>target: string &#124; string[]</code> | Resets blocking for a single instance or multiple instances by passing instance name(s). |
333+
| `resetGlobal` | <code>N/A</code> | Resets blocking app wide for all instances. |
309334
| `unsubscribe` | <code>target: string &#124; string[]</code> | Unsubscribes a single instance or multiple instances by passing instance name(s). |
310335
311336
## Other Modules
337+
312338
### [Http Module](docs/http-module.md) - Automatically block during http requests
339+
313340
### [Router Module](docs/router-module.md) - Prevent route changes while blocking
314341
315342
## Guides
343+
316344
### [Upgrading to 2.0.0](docs/migration-2.0.0.md)
345+
317346
### [SystemJS Config](docs/systemjs-config.md)
318347
319348
## Examples
349+
320350
### BlockUI Component - [Stackblitz](https://stackblitz.com/github/kuuurt13/ng-block-ui/tree/master/examples/default)
351+
321352
### BlockUI Component Default Message - [Stackblitz](https://stackblitz.com/github/kuuurt13/ng-block-ui/tree/master/examples/default-message)
353+
322354
### BlockUI Directive - [Stackblitz](https://stackblitz.com/github/kuuurt13/ng-block-ui/tree/master/examples/directive)
355+
323356
### BlockUI Custom Spinner Styles - [Stackblitz](https://stackblitz.com/github/kuuurt13/ng-block-ui/tree/master/examples/custom-spinner-styles)
357+
324358
### BlockUI Custom Template - [Stackblitz](https://stackblitz.com/github/kuuurt13/ng-block-ui/tree/master/examples/custom-template)

0 commit comments

Comments
 (0)