* Internal control directive creation lifecycle hook. * * The presence of this method tells the compiler to install `ɵɵControlFeature`, which will * cause this directive to be recognized as a control directive by the `ɵcontrolCreate` and * `ɵcontrol` instructions. * * @internal
(host: ControlDirectiveHost)
| 213 | * @internal |
| 214 | */ |
| 215 | protected ngControlCreate(host: ControlDirectiveHost): void { |
| 216 | const hasNgNoCva = host.nativeElement.hasAttribute?.('ngNoCva'); |
| 217 | const hasCva = |
| 218 | !hasNgNoCva && |
| 219 | ((this.rawValueAccessors && this.rawValueAccessors.length > 0) || |
| 220 | this.valueAccessor !== null); |
| 221 | |
| 222 | if (hasCva || !host.customControl) { |
| 223 | // This control is using the CVA pattern, so ngControlCreate is a noop. |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | this.isCustomControlBased = true; |
| 228 | |
| 229 | // Listen to custom control value changes -> update FormControl |
| 230 | // Note: We access this.control dynamically because it may not be set yet |
| 231 | // (e.g., FormControlDirective's form input hasn't been bound) |
| 232 | host.listenToCustomControlModel((value) => { |
| 233 | // TODO: is there a case where this input has not yet been set? |
| 234 | this.control?.setValue(value, {emitModelToViewChange: false}); |
| 235 | this.control?.markAsDirty(); |
| 236 | this.viewToModelUpdate(value); |
| 237 | }); |
| 238 | |
| 239 | // Listen to touched changes from FVC |
| 240 | host.listenToCustomControlOutput('touch', () => { |
| 241 | this.control?.markAsTouched(); |
| 242 | }); |
| 243 | |
| 244 | this.customControlBindings = {}; |
| 245 | this.isNativeFormElement = isNativeFormElement(host.nativeElement); |
| 246 | |
| 247 | this.requiredValidatorViaDi = this._rawValidators.find((v) => v instanceof RequiredValidator); |
| 248 | } |
| 249 | |
| 250 | protected ngControlUpdate(host: ControlDirectiveHost, bindRequired: boolean): void { |
| 251 | if (!this.isCustomControlBased) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…