console.log this.userForm.email을 시도하는 모델 기반 양식이 있지만 다음 오류가 발생합니다. 속성 'email'이 'FormGroup'유형에 존재하지 않습니다. 누구든지 도울 수 있습니까?
app.component.html
<div class="container">
<h2>User Data</h2>
<form [formGroup]="userForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" formControlName="name">
</div>
<div class="form-group">
<label>Email</label>
<input type="text" #refName class="form-control" formControlName="email">
<b>{{refName.className}}</b>
</div>
<div formGroupName="address">
<div class="form-group">
<label>Street</label>
<input type="text" class="form-control" formControlName="street">
</div>
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" formControlName="city">
</div>
<div class="form-group">
<label>PostalCode</label>
<input type="text" class="form-control" formControlName="postalcode">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { ReactiveFormsModule } from '@angular/forms'; // see peab olema
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ReactiveFormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms'
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
userForm = new FormGroup({
name: new FormControl('Brandon'),
email: new FormControl(),
address: new FormGroup({
street: new FormControl(),
city: new FormControl(),
postalcode: new FormControl()
})
});
onSubmit(){
console.log(this.userForm.email);
}
}
사용하는 this.userForm.controls.email.value
대신.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다