From 17a55264cea77d6cb008e82d1d56f7d2e71b5b45 Mon Sep 17 00:00:00 2001 From: Sam Severance Date: Fri, 25 Jan 2019 11:01:04 -0500 Subject: [PATCH] fix(examples): fix form-field custom control `disabled` input * fixes form-field custom control example and guide so as not to attempt to use the `disabled` attribute on an input element that has a reactive form directive. see: https://github.com/angular/angular/blob/e2c98fbe11272295c3827b0e54f859d283cd32bf/packages/forms/src/directives/reactive_errors.ts#L64 --- guides/creating-a-custom-form-field-control.md | 16 ++++------------ .../form-field-custom-control-example.ts | 1 + 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/guides/creating-a-custom-form-field-control.md b/guides/creating-a-custom-form-field-control.md index 4d5f219317ab..a6d3d8f98bd0 100644 --- a/guides/creating-a-custom-form-field-control.md +++ b/guides/creating-a-custom-form-field-control.md @@ -307,22 +307,14 @@ make up our component. ```ts @Input() -get disabled() { - return this._disabled; -} -set disabled(dis) { - this._disabled = coerceBooleanProperty(dis); +get disabled(): boolean { return this._disabled; } +set disabled(value: boolean) { + this._disabled = coerceBooleanProperty(value); + this._disabled ? this.parts.disable() : this.parts.enable(); this.stateChanges.next(); } private _disabled = false; ``` -```html - - - - - -``` #### `errorState` diff --git a/src/material-examples/form-field-custom-control/form-field-custom-control-example.ts b/src/material-examples/form-field-custom-control/form-field-custom-control-example.ts index 27ba34b0af77..60ef21b5e652 100644 --- a/src/material-examples/form-field-custom-control/form-field-custom-control-example.ts +++ b/src/material-examples/form-field-custom-control/form-field-custom-control-example.ts @@ -70,6 +70,7 @@ export class MyTelInput implements MatFormFieldControl, OnDestroy { get disabled(): boolean { return this._disabled; } set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); + this._disabled ? this.parts.disable() : this.parts.enable(); this.stateChanges.next(); } private _disabled = false;