订阅Web API的响应后,无法将响应数据分配给我的角度组件中的数组

问题描述

给出文件明智的代码段:

我有一个学生组件,用于获取订阅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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...