Skip to content

Commit 7fcb598

Browse files
committed
feat(docs): Show changes on param group
1 parent 38a609a commit 7fcb598

5 files changed

Lines changed: 41 additions & 16 deletions

File tree

projects/ngqp-demo/src/app/demo-browser/demo-browser.component.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
</div>
77
</div>
88

9-
<div *ngIf="refreshing" class="progress" [style.height.px]="1">
10-
<div class="progress-bar" role="progressbar" [style.width.%]="refreshProgress"></div>
9+
<div class="demo-browser__content">
10+
<ng-content></ng-content>
1111
</div>
1212

13-
<div class="demo-browser__content">
14-
<ng-container *ngIf="!refreshing">
15-
<ng-content></ng-content>
16-
</ng-container>
13+
<div *ngIf="group" class="demo-browser__console">
14+
({{ changeCounter }}) <ng-container *ngIf="lastChange">{{ lastChange }}</ng-container>
1715
</div>

projects/ngqp-demo/src/app/demo-browser/demo-browser.component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@
6868
padding: 16px;
6969
min-height: 120px;
7070
}
71+
72+
&__console {
73+
background: #eeeeee;
74+
border-top: 1px solid #e0e0e0;
75+
padding: 4px 8px;
76+
77+
font-size: small;
78+
color: #616161;
79+
}
7180
}

projects/ngqp-demo/src/app/demo-browser/demo-browser.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Component, Inject, Input } from '@angular/core';
1+
import { Component, Inject, Input, OnDestroy, OnInit } from '@angular/core';
22
import { Params } from '@angular/router';
3-
import { NGQP_ROUTER_ADAPTER, RouterAdapter } from '@ngqp/core';
3+
import { Subject } from 'rxjs';
4+
import { NGQP_ROUTER_ADAPTER, QueryParamGroup, RouterAdapter } from '@ngqp/core';
45
import { TestRouterAdapter } from '../test-router-adapter.service';
6+
import { takeUntil } from 'rxjs/operators';
57

68
@Component({
79
selector: 'demo-browser',
@@ -11,16 +13,38 @@ import { TestRouterAdapter } from '../test-router-adapter.service';
1113
{ provide: NGQP_ROUTER_ADAPTER, useClass: TestRouterAdapter },
1214
],
1315
})
14-
export class DemoBrowserComponent {
16+
export class DemoBrowserComponent implements OnInit, OnDestroy {
1517

1618
@Input()
1719
public set initialQueryParams(value: string) {
1820
this.updateQueryParams(value);
1921
}
2022

23+
@Input()
24+
public group: QueryParamGroup;
25+
26+
public changeCounter = 0;
27+
public lastChange: string;
28+
29+
private destroy$ = new Subject<void>();
30+
2131
constructor(@Inject(NGQP_ROUTER_ADAPTER) public routerAdapter: RouterAdapter) {
2232
}
2333

34+
public ngOnInit() {
35+
if (this.group) {
36+
this.group.valueChanges.pipe(takeUntil(this.destroy$)).subscribe(value => {
37+
this.changeCounter++;
38+
this.lastChange = JSON.stringify(value);
39+
});
40+
}
41+
}
42+
43+
public ngOnDestroy() {
44+
this.destroy$.next();
45+
this.destroy$.complete();
46+
}
47+
2448
public updateQueryParams(value: string) {
2549
const params: Params = {};
2650

projects/ngqp-demo/src/app/playground/playground.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<button type="button" (click)="setGroupValue()">Set Group</button>
44
-->
55

6-
<demo-browser initialQueryParams="?q=Hello+World">
6+
<demo-browser [group]="paramGroup" initialQueryParams="?q=Hello+World">
77
<ng-container [queryParamGroup]="paramGroup">
88
<input type="text" class="form-control" placeholder="Search" queryParamName="searchText" />
99

projects/ngqp-demo/src/app/playground/playground.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ export class PlaygroundComponent {
3131
emptyOn: 2,
3232
}),
3333
});
34-
35-
this.paramGroup.valueChanges
36-
.subscribe(value => console.log('group', { paramGroup: value }));
37-
38-
// this.paramGroup.get('searchText').valueChanges
39-
// .subscribe(value => console.log('searchText', { searchText: value }));
4034
}
4135

4236
public setSearchTextValue(value: string) {

0 commit comments

Comments
 (0)