在Angular 2中禁用按钮

41 components input button angular

我想如果输入'Contract type'为空,则按钮'Save'不可点击

保存按钮:

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

所有按钮:

 <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>
Run Code Online (Sandbox Code Playgroud)

定义合同类型:

 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.',
                }
            ]
        };
Run Code Online (Sandbox Code Playgroud)

按钮保存绿色:

在此输入图像描述

Rob*_*hof 74

更改ng-disabled="!contractTypeValid"[disabled]="!contractTypeValid"


Hie*_*yen 21

我尝试使用,[disabled]="!editmode"但在我的情况下不起作用。

这是我的解决方案[disabled]="!editmode ? 'disabled': null",我为谁担心。

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

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