Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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 如果选择了正确的选项,以角度4和反应形式显示元素_Angular_Angular Material - Fatal编程技术网

Angular 如果选择了正确的选项,以角度4和反应形式显示元素

Angular 如果选择了正确的选项,以角度4和反应形式显示元素,angular,angular-material,Angular,Angular Material,我对这个棱角分明的世界相当陌生,有一个需要满足的要求。我有一个下拉列表,其中填充了来自TS组件的值,四个值,最后一个是其他值。我希望看到的是,当在下拉列表中选择Other选项时,我只想显示该选项的输入元素。我用的是有棱角的材料,整个下午我都在努力解决这个问题 下面是我的代码 <div class="row"> <div class="col-md-4"> <mat-form-field> <mat-sel

我对这个棱角分明的世界相当陌生,有一个需要满足的要求。我有一个下拉列表,其中填充了来自TS组件的值,四个值,最后一个是其他值。我希望看到的是,当在下拉列表中选择Other选项时,我只想显示该选项的输入元素。我用的是有棱角的材料,整个下午我都在努力解决这个问题

下面是我的代码

 <div class="row">
      <div class="col-md-4">
        <mat-form-field>
          <mat-select placeholder="Company Type" formControlName="companyType"  #companyType required>
            <mat-option *ngFor="let companyType of companyTypes" [value]="companyType">
                  {{ companyType }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </div>

      <div ng-show="md-selected-text ==='Other'" class="col-md-8">
           <mat-form-field>
               <input matInput placeholder="Explain">
            </mat-form-field>                
      </div>
</div>

非常感谢您的帮助。

您可以使用以下工具:


*ngIf=“yourFormName.get('companyType')。value=='Other'”

您可以使用以下命令:


*ngIf=“yourFormName.get('companyType')。value==='Other'”

哇,谢谢@Alexandr2134,这很有帮助,而且它应该工作,下午大部分时间都在努力解决这个问题。哇,谢谢@Alexandr2134,这很有帮助,它应该工作,下午大部分时间都在努力解决这个问题。
export class HealthPlanComponent implements OnInit {
companyTypes = ['Health Insurance Company/HMO', 'Self-Insured Employee 
               Health Plan', 'Self-Insured Health & Welfare Fund', 'Other'];
}

submitTppClaim(): void {
    this.submitted = true;
    newClaim.companyType = this.consumerClaim.get('companyType').value;
      .subscribe(claim => {
      this.submitted = false;
      this.submittedClaim = claim;
      this.notSubmitted = false;
    });
}