angular - 如何使用表单以角度传递字段中的值?
问题描述
单击按钮时,我想将具有 formControlName 电子邮件的输入字段的值传递给该函数,有人可以给我一个想法或帮助吗?谢谢。
#html代码
<div>
<div fxLayout="column">
<mat-form-field class="full-width" appearance="fill" style="margin-top: 20px;">
<mat-label>Username</mat-label>
<input matInput placeholder="" autocomplete="email" formControlName="email">
<mat-error *ngIf="modelForm.get('email').hasError('required')">
Username is required.
</mat-error>
</mat-form-field>
</div>
<div style="text-align: right;">
<button (click)="getStarted()" mat-flat-button color="primary"
type="submit" class="v-btn-sml" id="get-started-button">
Submit
</button>
</div>
#.ts
getStarted() {
// I want to pass the input value from the username field here when button is clicked
}
private Form(): FormGroup {
return this.formBuilder.group({
id: [this.model.id || 0],
email: new FormControl(this.model.email, [Validators.required]),
});
}
解决方案
假设您已定义modelForm
为组件上的属性,
getStarted(){
const value = this.modelForm.value['email'];
}
推荐阅读
- spring - 在不使用 WSS4J 的情况下将 SAML 断言添加到 Spring Soap 请求
- flutter - 从 http 请求数据时出错
- javascript - 如何检索表单中的图像?
- amazon-web-services - AWS CodeBuild/CodePipeline 用户输入参数
- discord - discord.js Commando 自定义帮助命令
- python - 如何在 QWebEngineView 中允许语音识别 api
- c# - ListBox 按条件更改元素的文本颜色
- php - Laravel 集合不能使用箭头函数在地图内递增
- algorithm - 弗洛伊德循环检测在 O(n) 时间和 O(1) 空间中重复的数字
- sql - 使用绑定变量时的 SQL 无效标识符