使用字段集角材料禁止控制

问题描述 投票:0回答:2

我使用angular material 7.2.0。我试图禁止使用fieldset容器表单字段。输入控制它的工作原理,但不是mat-select。我知道我可以在这两个字段集和垫选声明它和它的作品,但我想更通用的代码来影响这一点。

我的代码示例:

<fieldset disabled="true">
    <form>
      <div>
          <label>סיבת הבדיקה</label>
          <mat-form-field>
            <mat-select>
              <mat-option [value]="undefined||null"></mat-option>
              <mat-option *ngFor="let reason of reasons"
                          [value]="reason.Code"
                          [matTooltip]="reason.Desc">
                {{reason.Desc}}
              </mat-option>
            </mat-select>
            <mat-error>
              חובה להזין ערך בשדה
            </mat-error>
          </mat-form-field>
        </div>
        <div>
            <label>הערות</label>
            <mat-form-field>
              <textarea maxlength="1200"></textarea>
            </mat-form-field>
        </div>
        <div>
            <label>מבצע</label>
            <mat-form-field>
              <input matInput
                     maxlength="100" />
              <mat-error>
                חובה להזין ערך בשדה
              </mat-error>
            </mat-form-field>
          </div>
    </form>
</fieldset>

任何想法?

angular angular-material disabled-control
2个回答
2
投票

使用CSS指针的事件属性

指针事件CSS属性设置在什么情况下(如果有的话)一个特定的图形元素可以成为指针事件的目标。

<fieldset [ngStyle]="{'pointer-events':true ? 'none' : 'none' }" >
  <mat-form-field>
    <mat-select placeholder="Select">
      <mat-option value="option">Option</mat-option>
    </mat-select>
  </mat-form-field>
</fieldset>

例如:https://stackblitz.com/edit/angular-ympzvr


0
投票

我通过删除字段集和设置形式,TS文件中使用ngAfterContentChecked事件禁用消除隔阂。

见所附链接如何使用它。

disable form

© www.soinside.com 2019 - 2024. All rights reserved.