简体   繁体   English

带角度不绑定的字符串插值

[英]String interpolation with angular not binding

I'm trying to bind the data to a template using string interpolation .我正在尝试使用字符串插值将数据绑定到模板。 When I am trying to refer the variable in the template, then it returns the following error:当我尝试引用模板中的变量时,它返回以下错误:

core.js:1350 ERROR TypeError: Cannot read property 'status' of undefined. core.js:1350 错误类型错误:无法读取未定义的属性“状态”。

HTML code : 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 is local variable scope only inside ngFor template that mean ul element here task是仅在ngFor模板内的局部变量范围,这意味着这里的 ul 元素

just move this span element to be inside `ngFor' template只需将此跨度元素移动到`ngFor'模板内

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

NgFor Local Variables NgFor 局部变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM