我正在尝试创建一个人员选择列表。
<div *ngIf="people">
<label>Tuoja</label>
<select [(ngModel)]="person" name="person" required>
<option *ngFor="let person of people" [value]="person.PersonID">
{{person.FirstName}} {{person.LastName}}
</option>
</select>
</div>
提交表单后,它会将ngForm
对象发送到typescript类:
sendNewMovie(movieForm: NgForm): void {
console.log(movieForm.value.person); // this is object
console.log(movieForm.value.movieName); // this is string
console.log(movieForm.value.movieDetails); // this is string
}
sendMovie函数在控制台中给出了这个,第一个控制台日志未定义,但其他日志工作:
undefined // this doesn't work
moviename // this works
moviedetails // this works
答案 0 :(得分:0)
修正了它
<div *ngIf="people">
<label>Tuoja</label>
<select [(ngModel)]="person" name="person" required>
<option *ngFor="let person of people" [value]="person.PersonID">
{{person.FirstName}} {{person.LastName}}
</option>
</select>
</div>
在组件中
console.log(movieForm.value.person);
console.log(movieForm.value.movieName);
console.log(movieForm.value.movieDetails);
输出
2
moviename
moviedetails