angular - Angular 6 Mat-Select does not define user.email through http GET request
问题描述
I want to make a select with a FormGroup. The data that the user can select from comes through a GET request.
Adminpanel.ts
this.userservice.getallusers().subscribe((res: any) =>{
for (let index = 0; index < res.length; index++) {
this.users[index] = res[index];
this.usersemails[index] = this.users[index].email;
console.log(this.usersemails[index]);
}
});
The data goes through a for loop and gets assigned to array usersemails[index]
.
The array gets filled up correct.
FormGroup from HTML
<form [formGroup]="AddxpForm" (ngSubmit)="addxponSubmit()">
<mat-form-field class="geo-full-width">
<input matInput placeholder="Amount of XP" type="number" name="User_xp" formControlName="user_xp">
</mat-form-field>
<mat-select placeholder="User email" name="useremail" fromControlName="useremail">
<mat-option *ngFor="let useremail of usersemails" [value]="useremail">
{{useremail}}
</mat-option>
</mat-select>
<button mat-raised-button class="geo-full-width" type="submit" [disabled]="!AddxpForm.valid">Add UserXP</button>
</form>
</div>
The select works also because I can select the emails I get through the HTTP GET request. But when I try to post it again the body email stays undefined
.
Submit function from ts file
addxponSubmit(){
this.user.email = this.AddxpForm.value.useremail;
this.user.experience = this.AddxpForm.value.user_xp
console.log(this.AddxpForm);
console.log(this.user);
}
can someone tell me what I do wrong here ?
解决方案
正如 fridoo 评论的那样,问题是错字,您可以在此处检查表单是否正常工作:
https://stackblitz.com/edit/mat-select-stack?embed=1&file=src/app/app.component.ts
推荐阅读
- c++ - 如何在 C++ 中使用 boost xml 从 xml 文件中读取特定值?
- locust - 如何使用 locust 中的路径变量聚合来自请求的统计信息?
- c# - EF 核心:为什么添加子行但自动添加父行项?
- javascript - 将 JsonResponse 数据(来自 Django 视图)作为 Javascript 中的 url 参数传递不起作用
- snowflake-cloud-data-platform - 将雪花表中的列修改为集群键
- spring - Spring Boot 等大型捆绑开源项目如何确保模块之间的兼容性?
- reactjs - Material-UI FormControl InputLabel显示问题
- python - 将 Pymongo 数据从列表附加到 pandas 数据框
- python - Python 中的 WAV 文件
- php - 无法弄清楚 .htaccess 到 web.config 重定向