我有一个mat-select
下拉菜单和一个input
字段。当button
点击它提交的数据。提交数据后,我想清除输入字段,但我不想清除mat-select
下拉列表。我怎样才能做到这一点?
chat.component.html
<div>
<mat-form-field>
<mat-select placeholder="Select User" [(ngModel)]="userObject.userid"
name="userid" required>
<mat-option *ngFor="let userObj of userObj [value]="userObj.userid">
{{userObj.username}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Type Message" [(ngModel)]="userObject.chatmessage">
</mat-form-field>
<button mat-raised-button color="primary" (click)="sendMessage()">
SEND MESSAGE</button>
</div>
由于您要双向绑定数据userObject.chatmessage
,因此只需在组件中将其设置为空字符串即可。
在您的ChatComponent
TypeScript类中,只需执行以下操作:
sendMessage() {
// After Sending Message
userObject.chatmessage = '';
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句