我有一个使用FormGroup构建的表单。
<form [formGroup]="signInForm"
(ngSubmit)="onSubmit(signInForm.value)"
class="ui form attached fluid">
<div class="field">
<div class="ui big left icon input">
<input type="text"
placeholder="Username"
[formControl]="signInForm.controls['username']">
<i class="user icon"></i>
</div>
</div>
<div class="field">
<div class="ui big left icon input">
<input placeholder="Password"
type="password"
[formControl]="signInForm.controls['password']">
<i class="lock icon"></i>
</div>
</div>
<button type="submit" class="big fluid ui blue submit button" disabled>Sign In</button>
</form>
组件类如下所示:
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
@Component({
selector: 'app-sign-in',
templateUrl: './sign-in.component.html',
styleUrls: ['./sign-in.component.css']
})
export class SignInComponent implements OnInit {
signInForm: FormGroup;
constructor(fb: FormBuilder) {
this.signInForm = fb.group({
'username': [],
'password': []
});
}
ngOnInit() {
}
onSubmit(value: object): void {
console.log('you submitted value:', value['username']);
}
}
考虑value
方法上的onSubmit
参数,它具有对象类型
我的问题是,我可以为参数value
指定一个类型,例如具有特定属性的类SignIn吗?