You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Sync URL Query Params with Angular Form Controls
16
16
17
-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ipsam iste iure, maxime modi molestiae nihil obcaecati odit officiis pariatur quibusdam suscipit temporibus unde.
18
-
Accusantium aliquid corporis cupiditate dolores eum exercitationem illo iure laborum minus nihil numquam odit officiis possimus quas quasi quos similique, temporibus veritatis? Exercitationem, iure magni nulla quo sapiente soluta. Esse?
17
+
The library provides a simple and reusable solution for binding URL query params to Angular Forms.
19
18
20
-
## Features
19
+
## Installation
21
20
22
-
- ✅ One
23
-
- ✅ Two
24
-
- ✅ Three
21
+
`npm install @ngneat/bind-query-params`
25
22
26
-
## Table of Contents
23
+
## Usage
27
24
28
-
-[Installation](#installation)
29
-
-[Usage](#usage)
30
-
-[FAQ](#faq)
25
+
Inject the `BindQueryParamsFactory` provider, pass an array of [defenitions](#QueryParamDefenition) and `connect` it to your form:
1. Update the `control`'s value when the page is loaded for the first time
62
+
2. Update the URL query parameter when the corresponding `control` value changes
37
63
38
-
### Yarn
64
+
##QueryParam Defenition
39
65
40
-
`yarn add @ngneat/bind-query-params --dev`
66
+
### `queryKey`
41
67
42
-
## Usage
68
+
The query parameter key
69
+
70
+
### `path`
43
71
44
-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ipsam iste iure, maxime modi molestiae nihil obcaecati odit officiis pariatur quibusdam suscipit temporibus unde.
72
+
The form control path. If it is not specified, the manager assumes that the `path` is the `queryKey`. We can also pass nested keys, for example, `person.name`:
45
73
46
74
```ts
47
-
function helloWorld() {}
75
+
{ queryKey: 'name', path: 'person.name'}
48
76
```
49
77
50
-
## FAQ
78
+
### `type`
79
+
80
+
Specify the control value type. Available options are:
81
+
`string`, `boolean`, `array`.
82
+
Before updating the control with the value, the manager will parse it based on the provided `type`.
83
+
84
+
### `parser`
85
+
86
+
Provide a custom parser. For example, the default `array` parser converts the value to an `array` of strings. If we need it to be an array of numbers, we can pass the following `parser`:
51
87
52
-
## How to ...
88
+
`{ parser: value => value.split(',').map(v => +v ) }`
53
89
54
-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ips
90
+
### `strategy`
91
+
92
+
When working with async control values, for example, a dropdown list that its options come from the server, we cannot immediately update the control.
93
+
94
+
In this cases, we can provide the `modelToUrl` strategy, that will not update the control value when the page loads. When the data is available we can call the `manager.syncDefs()` method that'll update the provided keys based on the current query params:
Note that `syncDefs` will always be called once under the hood.
130
+
131
+
## Browser Support
132
+
133
+
The library uses the [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API, which supported in any browser except IE.
55
134
56
135
## Contributors ✨
57
136
@@ -60,7 +139,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
60
139
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
0 commit comments