Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何禁用输入框角度2材质?_Angular_Typescript_Angular Material - Fatal编程技术网

Angular 如何禁用输入框角度2材质?

Angular 如何禁用输入框角度2材质?,angular,typescript,angular-material,Angular,Typescript,Angular Material,请先阅读我的描述 HTML文件 一个 两个 这里有一个解决方案 就这样改变方法吧 onChangeDisable() { if(this.One!=null && this.One!=''){ this.twoDisabled=true; }else{ this.twoDisabled=false; } } 我已经用你的stackblitz检查了这个密码,它正在工作 更新:- 下面是一个

请先阅读我的描述

HTML文件


一个
两个

这里有一个解决方案

就这样改变方法吧

 onChangeDisable() {
       if(this.One!=null && this.One!=''){
         this.twoDisabled=true;
       }else{
         this.twoDisabled=false;
       }
    }
我已经用你的stackblitz检查了这个密码,它正在工作

更新:-

下面是一个检查您的情况的示例

Html:-

  <input
      matInput
      [(ngModel)]="One"
      (ngModelChange)="onChangeDisable()"
      [disabled]="oneDisabled"
      />
这是给你的闪电战


这里有一个解决方案

就这样改变方法吧

 onChangeDisable() {
       if(this.One!=null && this.One!=''){
         this.twoDisabled=true;
       }else{
         this.twoDisabled=false;
       }
    }
我已经用你的stackblitz检查了这个密码,它正在工作

更新:-

下面是一个检查您的情况的示例

Html:-

  <input
      matInput
      [(ngModel)]="One"
      (ngModelChange)="onChangeDisable()"
      [disabled]="oneDisabled"
      />
这是给你的闪电战


首先通过设置
twoodisabled=false来启用两个输入。当用户在第一个输入中添加值,然后更改
twoodisabled=true

export class TableBasicExample {
  One: any;
  Two: any;
  twoDisabled = false;


  onChangeDisable() {
    if (!this.One) {
      this.twoDisabled = false;
    }
    else {
      this.twoDisabled = true;
    }
  }
}

你可以考虑第二个输入的逻辑,但是它也取决于不同的情况。类似:两个都有值,只有第二个输入有值…

两个输入都是通过首先设置
twodabled=false来启用的。当用户在第一个输入中添加值,然后更改
twoodisabled=true

export class TableBasicExample {
  One: any;
  Two: any;
  twoDisabled = false;


  onChangeDisable() {
    if (!this.One) {
      this.twoDisabled = false;
    }
    else {
      this.twoDisabled = true;
    }
  }
}

你可以考虑第二个输入的逻辑,但是它也取决于不同的情况。例如:两者都有值,只有第二个输入有值…

请尝试以下操作:

    export class TableBasicExample {
      One: any;
      Two: any;
      twoDisabled = false;

      onChangeDisable() {
        if (this.One) {
          this.twoDisabled = true;
        } else {
          this.twoDisabled = false;
        }
      }
    }

请尝试以下内容:

    export class TableBasicExample {
      One: any;
      Two: any;
      twoDisabled = false;

      onChangeDisable() {
        if (this.One) {
          this.twoDisabled = true;
        } else {
          this.twoDisabled = false;
        }
      }
    }

尝试一下:

import { Component } from '@angular/core';
import { MatTableDataSource } from '@angular/material';

@Component({...})
export class TableBasicExample {
  one: any;
  two: any;
  currentlyDisabled: string;

  onChangeDisable() {
    if(this.one) {
      this.currentlyDisabled = 'two';
    } else if (this.two) {
      this.currentlyDisabled = 'one';
    } else {
      this.currentlyDisabled = '';
    }
  }

}
在模板中:

<div class="row col-md-2">
   <mat-form-field appearance="outline" class="nameInput col-md-2">
      <mat-label>One</mat-label>
      <input
        matInput
        [(ngModel)]="one"
        (change)="onChangeDisable()"
        [disabled]="currentlyDisabled === 'one'"
      />
   </mat-form-field>
</div>
<div class="row col-md-2">
   <mat-form-field
      appearance="outline"
      class="nameInput col-md-2"
      >
      <mat-label>Two</mat-label>
      <input
        matInput
        [(ngModel)]="two"
        (change)="onChangeDisable()"
        [disabled]="currentlyDisabled === 'two'"
      />
   </mat-form-field>
</div>

一个
两个

这是给你的裁判的一封信

尝试一下:

import { Component } from '@angular/core';
import { MatTableDataSource } from '@angular/material';

@Component({...})
export class TableBasicExample {
  one: any;
  two: any;
  currentlyDisabled: string;

  onChangeDisable() {
    if(this.one) {
      this.currentlyDisabled = 'two';
    } else if (this.two) {
      this.currentlyDisabled = 'one';
    } else {
      this.currentlyDisabled = '';
    }
  }

}
在模板中:

<div class="row col-md-2">
   <mat-form-field appearance="outline" class="nameInput col-md-2">
      <mat-label>One</mat-label>
      <input
        matInput
        [(ngModel)]="one"
        (change)="onChangeDisable()"
        [disabled]="currentlyDisabled === 'one'"
      />
   </mat-form-field>
</div>
<div class="row col-md-2">
   <mat-form-field
      appearance="outline"
      class="nameInput col-md-2"
      >
      <mat-label>Two</mat-label>
      <input
        matInput
        [(ngModel)]="two"
        (change)="onChangeDisable()"
        [disabled]="currentlyDisabled === 'two'"
      />
   </mat-form-field>
</div>

一个
两个

这是给你的裁判的一封信


很多答案,但你张贴的答案其实我想要谢谢你先生!很高兴帮助你。。谢谢。有很多答案,但你把答案贴在我想要的地方。谢谢你,先生!很高兴帮助你。。谢谢。谢谢,先生,您的代码按我的要求工作,但当我单击输入框时,输入框被禁用谢谢,先生,您的代码按我的要求工作,但当我单击输入框时,输入框被禁用