Angular 应用程序尝试使用 API 调用的结果填充选择中的选项:
<select class="select input input-bordered" formControlName="student" (change)="onStudentChange($event)" >
<option *ngFor="let student of students" value="{{student._id}}">{{ student.name }}</option>
</select>
初始化:
ngOnInit(): void {
this.userService.getStudentsByUser(this.authService.currentUserSig()?._id!).subscribe((response) => {
this.students = response;
});
}
我这里漏掉了什么?在本地调试时,我保存了 html 文件,然后它神奇地填充了,但刷新后它就消失了。