Skip to content

Commit

Permalink
fix(module:input): support reactive form disabled (#5316)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuonuoge authored Jun 16, 2020
1 parent f99d7ff commit 8270009
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions components/input/input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Directive, ElementRef, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';
import { Directive, ElementRef, Input, OnChanges, Optional, Renderer2, Self, SimpleChanges } from '@angular/core';
import { NgControl } from '@angular/forms';
import { BooleanInput, NzSizeLDSType } from 'ng-zorro-antd/core/types';
import { InputBoolean } from 'ng-zorro-antd/core/util';
import { Subject } from 'rxjs';

@Directive({
Expand All @@ -22,10 +22,20 @@ export class NzInputDirective implements OnChanges {
static ngAcceptInputType_disabled: BooleanInput;

@Input() nzSize: NzSizeLDSType = 'default';
@Input() @InputBoolean() disabled = false;
@Input()
get disabled(): boolean {
if (this.ngControl && this.ngControl.disabled !== null) {
return this.ngControl.disabled;
}
return this._disabled;
}
set disabled(value: boolean) {
this._disabled = value != null && `${value}` !== 'false';
}
_disabled = false;
disabled$ = new Subject<boolean>();

constructor(renderer: Renderer2, elementRef: ElementRef) {
constructor(@Optional() @Self() public ngControl: NgControl, renderer: Renderer2, elementRef: ElementRef) {
renderer.addClass(elementRef.nativeElement, 'ant-input');
}
ngOnChanges(changes: SimpleChanges): void {
Expand Down

0 comments on commit 8270009

Please sign in to comment.