角度:错误类型错误:无法读取未定义的属性___

约翰·C

即使这些值在浏览器中呈现,我也会遇到这些错误。我不确定如何解决此问题。

错误TypeError:无法读取未定义的属性'length'

错误TypeError:无法读取未定义的属性'FirstName'

Component.ts:

teams: Team[];

ngOnInit() {
  this.getTeams();
}

constructor(private m: DataManagerService, private router: Router) { 
}

getTeams(): void {
  this.m.getTeams().subscribe(teams => this.teams = teams);
}

select(em: Team){
  this.router.navigate(['/teamView',em._id]);
}

Component.html:

<div class="panel-body">
  <table class="table table-striped">
    <tr>
      <th>Team name</th>
      <th>Name of Team Leader</th>
    </tr>
    <tr *ngFor='let team of teams' (click)="select(team)">
      <td>{{team.TeamName}}</td>
      <td>{{team.TeamLead.FirstName}} {{team.TeamLead.LastName}}</td>
    </tr>
  </table>
  <hr>
</div>

Team.ts:

export class Team {
    _id: string;
    TeamName: string;
    TeamLead: Employee;
    Projects:{};
    Employees: {};
}

目的:

https://lit-coast-73093.herokuapp.com/teams

DataManagerService.ts

teams: Team[];
projects: Project[];
employees: Employee[];

constructor(private http: HttpClient) { 
}

getTeams(): Observable<Team[]> {
    return this.http.get<Team[]>(`${this.url}/teams`)
  }

getProjects(): Observable<Project[]> {
    return this.http.get<Project[]>(`${this.url}/projects`)
}

getEmployees(): Observable<Employee[]> {
    return this.http.get<Employee[]>(`${this.url}/employees`)
}
比马尔·保罗
<tr *ngIf='teams.length > 0' *ngFor='let team of teams' (click)="select(team)">
  <td>{{team?.TeamName}}</td>
  <td>{{team?.TeamLead?.FirstName}} {{team?.TeamLead?.LastName}}</td>
</tr>

可能性:a)尚未填充Teams对象。因此,没有什么可重复的b)您的API响应没有所有预期的属性。

像我上面建议的那样添加检查应该可以解决您的问题。LMK,如果我可以进一步解释。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误TypeError:无法读取角度未定义的属性'closeRow'

角度-错误TypeError:无法读取未定义的属性'title'

错误类型错误:无法读取未定义的属性“标题”

错误类型错误:无法读取未定义的属性“...”

错误类型错误:无法读取未定义的属性“填充”

类型错误:无法读取未定义的属性“indexOf”,无法读取未定义的属性“toLowerCase”

错误类型错误:无法读取未定义的属性“stateName”

错误类型错误:无法读取未定义的属性

错误类型错误:无法读取未定义的属性“getUsers”

“类型错误:无法读取未定义的属性‘名称’”错误

角度:错误错误:未捕获(承诺):类型错误:无法读取未定义的属性“设置”

类型错误:无法读取未定义的属性“类型”

错误类型错误:无法读取未定义的属性“列表”

类型错误:无法读取未定义的属性“ChangeClassName”

错误类型错误:无法读取未定义的角度 8 的属性“长度”

错误类型错误:无法读取未定义的属性“_id”

角度路由给出错误类型错误:无法读取未定义的属性“init”

渲染错误:“类型错误:无法读取未定义的属性‘’”

类型错误:无法读取未定义错误的属性“_id”

错误类型错误:无法读取未定义的 ngx-translate 角度打字稿的属性“即时”

错误类型错误:无法读取未定义的属性“doc”

类型错误:无法在 setTimeout() 中读取未定义的属性“then”

**错误** 类型错误:无法读取未定义的属性“替换”

类型错误:无法读取未定义的属性(读取“图像”)

类型错误:无法读取未定义的属性(读取“缓存”)

类型错误:无法读取未定义的属性(读取“暗”)

类型错误:无法读取未定义的属性(读取“reduce”)

类型错误:无法读取未定义的属性(读取“类型”)

类型错误:无法读取未定义读取“2”的属性