如何使用angular2绑定html页面中的值?

时间:2017-11-27 10:17:10

标签: angular typescript

我在使用我的代码时遇到以下错误: 错误:未捕获(在承诺中):TypeError:无法获取未定义或空引用的属性“标准” 下面是我的代码: student.component.ts:

 this._studentService.get(Global.BASE_USER_ENDPOINT + '/StudentDetailsApi?user_id=' + StudID)
                .do(data => JSON.stringify(data))
                .subscribe(students=> { this.students= students; this.indLoading = false; },
                error => this.msg = <any>error);

和student.component.html:

<span>{{student.standard}}</span>

1 个答案:

答案 0 :(得分:0)

添加空检查

  var Studentsession = JSON.parse(sessionStorage.getItem('student_session'));
  if(Studentsession){
    this.student.StudRollNo = Studentsession[0].StudRollNo;
    this.student.StudName = Studentsession[0].StudName;
    this.student.Standard = Studentsession[0].Standard;
  }