使用fieldset禁用角度材质控件

时间:2019-02-10 12:55:18

标签: angular angular-material disabled-control

我正在使用angular material 7.2.0。 我正在尝试使用fieldset容器禁用表单字段。 适用于输入控件,但不适用于mat-select。 我知道我可以在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>

有什么主意吗?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我通过删除字段集并将表单设置为在ts文件中使用ngAfterContentChecked事件禁用来解决该问题。

请参阅附件的链接。

disable form

相关问题