Skip to content

Commit 4758650

Browse files
committed
docs(asyncpipe): add async pipe demo example
1 parent e325ebc commit 4758650

6 files changed

Lines changed: 99 additions & 2 deletions

File tree

projects/ng-sortgrid-demo/src/app/app.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<div class="container">
55
<h1>1. Getting started</h1>
6-
<ngsg-demo-step title="Loop over your elements with *ngFor. 🛎️ the items needs to be an array." image="gs1.png"></ngsg-demo-step>
6+
<ngsg-demo-step title="Loop over your elements with *ngFor. 🛎️ the items needs to be an array. Alternate you can also use the async pipe - see below" image="gs1.png"></ngsg-demo-step>
77
<ngsg-demo-step title="Apply the ngSortgridItem directive" image="gs2.png"></ngsg-demo-step>
88
<ngsg-demo-memory></ngsg-demo-memory>
99

@@ -22,6 +22,11 @@ <h1>3. Group sortgrids</h1>
2222
one group in another group.</p>
2323
<ngsg-demo-step title="Pass in a unique name to the ngSortGridGroup input" image="gs5.png"></ngsg-demo-step>
2424
<ngsg-demo-groups-memory></ngsg-demo-groups-memory>
25+
26+
<hr class="chaptor-separator"/>
27+
<h1>4. Use the async pipe</h1>
28+
<ngsg-demo-step title="Use the async pipe to loop over the items and to pass in the ngSortGridItems" image="gs6.png"></ngsg-demo-step>
29+
<ngsg-demo-async></ngsg-demo-async>
2530
</div>
2631

2732
<footer class="py-5 bg-dark">

projects/ng-sortgrid-demo/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {StepComponent} from './examples/step/step.component';
1010
import {ReactOnChangesMemoryComponent} from './examples/react-on-changes/react-on-changes-memory.component';
1111
import {GroupsMemoryComponent} from './examples/groups/groups-memory.component';
1212
import {CardComponent} from './examples/card/card.component';
13+
import {AsyncPipeMemoryComponent} from './examples/async-pipe/async-pipe-memory.component';
1314

1415
@NgModule({
1516
declarations: [
@@ -20,7 +21,8 @@ import {CardComponent} from './examples/card/card.component';
2021
StepComponent,
2122
ReactOnChangesMemoryComponent,
2223
GroupsMemoryComponent,
23-
CardComponent
24+
CardComponent,
25+
AsyncPipeMemoryComponent
2426
],
2527
imports: [BrowserModule, NgsgModule],
2628
providers: [],
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.spinner {
2+
width: 40px;
3+
height: 40px;
4+
5+
position: relative;
6+
margin: 100px auto;
7+
}
8+
9+
.double-bounce1, .double-bounce2 {
10+
width: 100%;
11+
height: 100%;
12+
border-radius: 50%;
13+
background-color: #333;
14+
opacity: 0.6;
15+
position: absolute;
16+
top: 0;
17+
left: 0;
18+
19+
-webkit-animation: sk-bounce 2.0s infinite ease-in-out;
20+
animation: sk-bounce 2.0s infinite ease-in-out;
21+
}
22+
23+
.double-bounce2 {
24+
-webkit-animation-delay: -1.0s;
25+
animation-delay: -1.0s;
26+
}
27+
28+
@-webkit-keyframes sk-bounce {
29+
0%, 100% { -webkit-transform: scale(0.0) }
30+
50% { -webkit-transform: scale(1.0) }
31+
}
32+
33+
@keyframes sk-bounce {
34+
0%, 100% {
35+
transform: scale(0.0);
36+
-webkit-transform: scale(0.0);
37+
} 50% {
38+
transform: scale(1.0);
39+
-webkit-transform: scale(1.0);
40+
}
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<h5 style="margin-bottom: 20px">4. Load items and use them with the async pipe</h5>
2+
<button style="margin-bottom: 20px" class="btn btn-primary" (click)="loadItems()">Load items</button>
3+
<div class="card border-primary mb-3">
4+
<div class="card-body">
5+
<h1 class="card-title">Sort order</h1>
6+
<h2 class="card-text">{{ sortOrder }}</h2>
7+
</div>
8+
</div>
9+
<div class="example-container">
10+
<div *ngIf="loading" class="spinner">
11+
<div class="double-bounce1"></div>
12+
<div class="double-bounce2"></div>
13+
</div>
14+
<ngsg-card *ngFor="let item of item$ | async"
15+
ngSortgridItem
16+
[ngSortGridItems]="item$ | async"
17+
[item]="item"
18+
(sorted)="applyOrder($event)"
19+
class="example-box">
20+
</ngsg-card>
21+
</div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Component} from '@angular/core';
2+
import {Observable, of} from 'rxjs';
3+
import {delay, tap} from 'rxjs/operators';
4+
5+
@Component({
6+
selector: 'ngsg-demo-async',
7+
templateUrl: './async-pipe-memory.component.html',
8+
styleUrls: ['./async-pipe-memory.component.css', '../memory-demo.css']
9+
})
10+
export class AsyncPipeMemoryComponent {
11+
12+
item$: Observable<number[]>;
13+
loading = false;
14+
public sortOrder: number[];
15+
16+
public loadItems(): void {
17+
this.loading = true;
18+
this.item$ = of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).pipe(
19+
delay(1500),
20+
tap(() => this.loading = false)
21+
);
22+
}
23+
24+
public applyOrder(newOrder: number[]): void {
25+
this.sortOrder = newOrder;
26+
}
27+
28+
}
81.8 KB
Loading

0 commit comments

Comments
 (0)