问题描述
给出文件明智的代码段:
我有一个学生组件,用于获取订阅http响应并分配给我的数组学生 组件:
export class StudentComponent implements OnInit {
public students: IStudentDetails[];
showMsgDiv = false;
constructor(private _studentService: StudentService) { }
ngOnInit() {
this.getStudents();
//console.log(this.students == null);
if (this.students == null) {
this.showMsgDiv = true;
}
**getStudents() {
this._studentService.getStudents().subscribe(
responseStudentData => {
this.students = responseStudentData;
//console.log(this.students);
this.showMsgDiv = false;
});
}**
}
Service :
用于以可观察的方式获取get响应的服务
export class StudentService {
constructor(private http: HttpClient) { }
getStudents(): Observable<IStudentDetails[]> {
let tempVar = this.http.get<IStudentDetails[]>('https://localhost:44343/api/student');
return tempVar;
}
}
用于定义学生详细信息及其相关属性的界面
Interface:
export interface IStudentDetails {
studentId: Number;
firstName: String;
lastName: String;
class: Number;
subject: String;
totalMarks: Number;
}
I can see in browser console that my the responseStudentData is getting populated but it is not assigning to the students array.
Console.log statements are commented in the code attached above . The same are used for the image.
[1]: https://i.stack.imgur.com/MKLWD.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)