File tree Expand file tree Collapse file tree
projects/ngqp-demo/src/app
examples/add-remove-parameter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import { GlobalConfigurationDocsComponent } from './docs-items/global-configurat
3434import { CustomControlValueAccessorDocsComponent } from './docs-items/custom-control-value-accessor/custom-control-value-accessor-docs.component' ;
3535import { ControlValueAccessorDirectiveExampleComponent } from './docs-items/examples/control-value-accessor-directive-example/control-value-accessor-directive-example.component' ;
3636import { ManualWiringExampleComponent } from './docs-items/examples/manual-wiring-example/manual-wiring-example.component' ;
37+ import { AddRemoveParameterExampleComponent } from './docs-items/examples/add-remove-parameter/add-remove-parameter-example.component' ;
3738import { ServiceWorkerModule } from '@angular/service-worker' ;
3839import { environment } from '../environments/environment' ;
3940
@@ -73,6 +74,7 @@ import { environment } from '../environments/environment';
7374 CustomControlValueAccessorDocsComponent ,
7475 ControlValueAccessorDirectiveExampleComponent ,
7576 ManualWiringExampleComponent ,
77+ AddRemoveParameterExampleComponent ,
7678 ] ,
7779 imports : [
7880 BrowserModule ,
Original file line number Diff line number Diff line change 1+ < demo-example [markup] ="markup " [typescript] ="typescript ">
2+ < demo-browser [group] ="paramGroup " initialQueryParams ="?q=Hello+World ">
3+ < ng-container [queryParamGroup] ="paramGroup ">
4+ < div class ="alert alert-primary ">
5+ Use the button to add or remove the parameter bound to the input field. Try typing or changing the URL
6+ when the parameter is detached.
7+ </ div >
8+
9+ < div class ="input-group ">
10+ < div class ="input-group-prepend ">
11+ < button type ="button " class ="btn btn-primary " (click) ="toggleParam() ">
12+ < ng-container *ngIf ="hasParam "> Remove Parameter</ ng-container >
13+ < ng-container *ngIf ="!hasParam "> Add Parameter</ ng-container >
14+ </ button >
15+ </ div >
16+
17+ < input type ="text " autocomplete ="off " class ="form-control " [queryParamName] ="hasParam ? 'param' : null " />
18+ </ div >
19+ </ ng-container >
20+ </ demo-browser >
21+ </ demo-example >
Original file line number Diff line number Diff line change 1+ import { Component } from '@angular/core' ;
2+ import { QueryParamBuilder , QueryParamGroup } from '@ngqp/core' ;
3+
4+ declare const require : Function ;
5+
6+ @Component ( {
7+ selector : 'demo-add-remove-parameter-example' ,
8+ templateUrl : './add-remove-parameter-example.component.html' ,
9+ } )
10+ export class AddRemoveParameterExampleComponent {
11+
12+ public paramGroup : QueryParamGroup ;
13+
14+ public markup = require ( '!raw-loader!./add-remove-parameter-example.component.html' ) ;
15+ public typescript = require ( '!raw-loader!./add-remove-parameter-example.component.ts' ) ;
16+
17+ constructor ( private qpb : QueryParamBuilder ) {
18+ this . paramGroup = qpb . group ( { } ) ;
19+
20+ // Let's activate it by default
21+ this . toggleParam ( ) ;
22+ }
23+
24+ public get hasParam ( ) : boolean {
25+ return ! ! this . paramGroup . get ( 'param' ) ;
26+ }
27+
28+ public toggleParam ( ) {
29+ if ( this . hasParam ) {
30+ this . paramGroup . remove ( 'param' ) ;
31+ } else {
32+ const param = this . qpb . stringParam ( 'q' ) ;
33+ this . paramGroup . add ( 'param' , param ) ;
34+ }
35+ }
36+
37+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,16 @@ <h3>Accessing individual parameters</h3>
2222 </ p >
2323 < demo-snippet type ="typescript " [code] ="qpgGetSnippet "> </ demo-snippet >
2424
25+ < docs-fragment fragment ="QueryParamGroup-add-remove ">
26+ < h3 > Adding and removing parameters</ h3 >
27+ </ docs-fragment >
28+ < p >
29+ You can dynamically add or remove parameters to or from a group by using < span apiDocsLink > QueryParamGroup#add</ span >
30+ and < span apiDocsLink > QueryParamGroup#remove</ span > , respectively. Adding a parameter will resynchronize the entire
31+ group with the URL.
32+ </ p >
33+ < demo-add-remove-parameter-example > </ demo-add-remove-parameter-example >
34+
2535 < docs-fragment fragment ="QueryParamGroup-value ">
2636 < h3 > Reading the current value</ h3 >
2737 </ docs-fragment >
You can’t perform that action at this time.
0 commit comments