提交角度数据后如何清除输入字段?

用户名

我有一个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>
悉达(SiddAjmera)

由于您要双向绑定数据userObject.chatmessage,因此只需在组件中将其设置为空字符串即可。

在您的ChatComponentTypeScript类中,只需执行以下操作:

sendMessage() {
  // After Sending Message
  userObject.chatmessage = '';
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章