Disable button in Angular 2

I want if the input "Contract type" is empty, the "Save" button is not active

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>

      

The definition of 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.',
                }
            ]
        };

      

KEEP GREEN BUTTON:

enter image description here

+31


source to share


2 answers


Change ng-disabled="!contractTypeValid"

to[disabled]="!contractTypeValid"



+55


source


I tried to use it [disabled]="!editmode"

but it didn't work in my case.

This is my decision [disabled]="!editmode? 'disabled': ''"

, I share the concern for whom.



<button [disabled]="!editmode ? 'disabled': ''" 
    (click)='loadChart()'>
            <div class="btn-primary">Load Chart</div>
    </button>

      

Stackbliz https://stackblitz.com/edit/angular-af55ep

0


source







All Articles