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
Currently the `nativeElement` in all of the `ElementRef` usages is typed to be `any`. These changes add proper typing to help us catch some errors at compile time.
This property allows the form field control to specify the `@angular/forms` control that is bound to this component. Since we haven't set up our component to act as a `ControlValueAccessor`, we'll just set this to `null` in our component.
162
+
This property allows the form field control to specify the `@angular/forms` control that is bound to this component. Since we haven't set up our component to act as a `ControlValueAccessor`, we'll just set this to `null` in our component.
163
163
164
164
```ts
165
165
ngControl: NgControl=null;
166
166
```
167
167
168
-
It is likely you will want to implement `ControlValueAccessor` so that your component can work with `formControl` and `ngModel`. If you do implement `ControlValueAccessor` you will need to get a reference to the `NgControl` associated with your control and make it publicly available.
168
+
It is likely you will want to implement `ControlValueAccessor` so that your component can work with `formControl` and `ngModel`. If you do implement `ControlValueAccessor` you will need to get a reference to the `NgControl` associated with your control and make it publicly available.
169
169
170
170
The easy way is to add it as a public property to your constructor and let dependency injection handle it:
171
171
172
172
```ts
173
173
constructor(
174
-
...,
174
+
...,
175
175
@Optional() @Self() publicngControl: NgControl,
176
176
...,
177
177
) { }
178
178
```
179
179
180
-
Note that if your component implements `ControlValueAccessor`, it may already be set up to provide `NG_VALUE_ACCESSOR` (in the `providers` part of the component's decorator, or possibly in a module declaration). If so you may get a *cannot instantiate cyclic dependency* error.
180
+
Note that if your component implements `ControlValueAccessor`, it may already be set up to provide `NG_VALUE_ACCESSOR` (in the `providers` part of the component's decorator, or possibly in a module declaration). If so you may get a *cannot instantiate cyclic dependency* error.
181
181
182
182
To resolve this, remove the `NG_VALUE_ACCESSOR` provider and instead set the value accessor directly:
183
183
184
184
```ts
185
185
constructor(
186
-
...,
186
+
...,
187
187
@Optional() @Self() publicngControl: NgControl,
188
188
...,
189
189
) {
@@ -207,7 +207,7 @@ need to remember to emit on the `stateChanges` stream so change detection can ha
0 commit comments