我有一个下拉列表,其中包含:父亲,母亲和监护人。后跟一个没有占位符的输入文本框。我希望文本框的占位符根据所选的值动态更新
我尝试使用ts文件部分中的占位符属性分配字符串。但它只能选择该特定值。我想用* ngIf
选择 this is the select drop-down
<mat-select placeholder="Relation to Student"formControlName="relationType">
<mat-option *ngFor="let relation of relationType" [value]="relation">
{{ relation }}
</mat-option>
</mat-select>
this is the html input
<input matInput placeholder="{{related}} " formControlName="fatherFullName" required>
this is the ts and i know this isn't how it works. i'm sure of adding an "if" but i'm not sure of how to do it
related = ' Father's full name';
我期望这样的结果:如果在选择下拉列表中选择了父亲,则输入文本框中的占位符应为父亲的全名。
谢谢!
答案 0 :(得分:0)
嗨,我想这就是你要的:
在您的html中
<mat-form-field class="example-full-width">
<input matInput placeholder="{{str}}" value="Sushi">
</mat-form-field>
<mat-form-field class="example-full-width">
<mat-select [(ngModel)]="changeData" (ngModelChange)="test()" name="dropBox">
<mat-option value="relation1">relation1</mat-option>
<mat-option value="relation2">relation2</mat-option>
<mat-option value="relation3">relation3</mat-option>
</mat-select>
</mat-form-field>
现在在您的ts文件中
str = '';
changeData:any ;
test(){
console.log("rest");
this.str = this.changeData;
}