programing

Angular 2에서 버튼 비활성화

mytipbox 2023. 8. 26. 15:38
반응형

Angular 2에서 버튼 비활성화

'계약 유형' 입력이 비어 있으면 '저장' 버튼을 클릭할 수 없습니다.

저장 버튼:

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

모든 단추:

 <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>

정의 계약 유형:

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

버튼 녹색 저장:

enter image description here

바꾸다ng-disabled="!contractTypeValid"로.[disabled]="!contractTypeValid"

사용해 보았습니다.[disabled]="!editmode"하지만 제 경우에는 안 됩니다.

이것이 나의 해결책입니다.[disabled]="!editmode ? 'disabled': null"나는 누구와 관련이 있는지 공유합니다.

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

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

언급URL : https://stackoverflow.com/questions/43978380/disable-button-in-angular-2

반응형