Disable Button in Angular 2

user7325116 picture user7325116 · May 15, 2017 · Viewed 134.6k times · Source

I want if the input 'Contract type' is empty, the button 'Save' is not clickable

Save button:

<div class="col-md-4">
        <cic-textbox [control]="formGroup.get('contractType')"></cic-textbox>
      </div>

ALL Buttons:

 <div class="cic-header-actions pull-left" *ngIf="actions && actions.length > 
 0">
      <button class="btn btn-{{action.style}} m-l-xs" *ngFor="let action of actions" ng-disabled="!contractTypeValid" (click)="execute(action)">
          <cic-icon [icon]="action.icon"></cic-icon>
          {{action.text }}
        </button>
    </div>

Definition contractType:

 let contractType: DataDictionaryPropertyExtended = {
            Binding: 'VART:BEZEICHNUNG',
            Label: 'Vertragsart',
            LabelCols: 4,
            ContentCols: 8,
            IsDisabled: this.isDisabled,
            ValidationProperties: [
                <ValidationProperty>{
                    Type: ValidationType.IsNotEmpty,
                    ErrorMessage: 'Vertragsart darf nicht leer sein.',
                }
            ]
        };

BUTTON SAVE GREEN:

enter image description here

Answer

Robin Dijkhof picture Robin Dijkhof · May 15, 2017

Change ng-disabled="!contractTypeValid" to [disabled]="!contractTypeValid"