gpt4 book ai didi

javascript - Angular 不绑定(bind)的字符串插值

转载 作者:搜寻专家 更新时间:2023-10-30 21:36:04 25 4
gpt4 key购买 nike

我正在尝试使用字符串插值 将数据绑定(bind)到模板。当我尝试引用模板中的变量时,它返回以下错误:

core.js:1350 ERROR TypeError: Cannot read property 'status' of undefined.

HTML代码:

<div class="chat-main">
<div class="col-md-12 chat-header rounded-top bg-primary text-white hide-chat-box">
<div class="row">
<div class="col-md-6 username pl-2">
<h6 class="m-0">&nbsp;&nbsp; &nbsp;Tasks</h6>&nbsp;
<span class="badge" style="background: red">{{ task?.status?.length }}</span>
</div>
<div class="col-md-6 options text-right pr-2">
<i class="fa fa-window-minimize" aria-hidden="true"></i>
</div>
</div>
</div>
<div class="chat-content">
<div class="col-md-12 chats border">
<br/>
<ul class="p-0" *ngFor="let task of tasksRes">
<li class="pl-2 pr-2 text-dark send-msg mb-1">
<div>
<a href="javascript:;" [routerLink]="[task.link]" style="text-decoration: none !important;">
<span class="text-warning" *ngIf="task.status == 'In_progress'"><i class="fa fa-spinner fa-spin"></i></span>
<span class="text-success" *ngIf="task.status == 'Done'"><i class="fa fa-check"></i></span>
<span>&nbsp;&nbsp;{{ task.name }}</span>
</a>
<br/>
<span class="pull-right text-muted">{{task.createdDate | timeAgo}}</span>&nbsp;&nbsp;
<span class="text-muted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{task.eventType}}</span>
</div>
</li>
</ul>
</div>
</div>
</div>

最佳答案

task 是仅在 ngFor 模板内的局部变量范围,这意味着此处的 ul 元素

只需将这个 span 元素移动到 `ngFor' 模板中

<span class="badge" style="background: red">{{ task?.status?.length }}</span>

NgFor Local Variables

关于javascript - Angular 不绑定(bind)的字符串插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51943810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com