javascript - Angular 6调用方法并将值分配给*ngFor中的变量
问题描述
我想在里面调用一个方法ngFor
,想把返回值赋给一个局部变量。我尝试了这种方法:
<div *ngFor="let card of partNumberPlanningCards; let i = index" class="partnumber-basic-card">
<div
*ngFor="let scope of containerScopeLineItems; let lineItem = getOperatingWeightBy(scope.containerScopeId, card.typeId)">
</div>
</div>
但它显示了这个错误:
Parser Error: Unexpected token (, expected identifier, keyword, or string at column 74 in [let scope of containerScopeLineItems; let lineItem = getOperatingWeightBy(scope.containerScopeId, card.typeId)] in ng
解决方案
您可以将function
返回值存储在任何 of 中attribute
,element
并使用element
引用来获取值。
<div *ngFor="let card of partNumberPlanningCards; let i = index" class="partnumber-basic-card">
<div *ngFor="let scope of containerScopeLineItems" #lineItem [title]="getOperatingWeightBy(scope.containerScopeId, card.typeId)">
{{lineItem.title}}
</div>
</div>
此处title
已使用,但您可以使用元素的任何有效属性。
推荐阅读
- chart.js - 在雷达图中隐藏数据集的数据?
- asp.net-core - 创建用于过滤名称、价格和可用性的端点
- xml - Python 2.6.6:无法从当前元素的直接子元素中提取文本
- python - 如何在 python 中向生成器发送数据
- javascript - 相对于世界时钟,每 15 分钟后将每个 div 的位置顺时针替换 1 步
- entity-framework - 在 EFCore 中关闭全局过滤器警告
- debugging - 在 Visual Studio Code 中使用 Makefile 调试现有项目
- java - 在项目上单击每个项目在回收站视图中,我想替换 viewpager2 中的片段
- antd - 如何从 ant design pro v5 中删除 WaterMark?
- android - Play 商品详情