在 html 角度打字稿上过滤数组

时间:2021-05-21 05:28:04

标签: javascript angular

我有一个这样的数组:

documents = [
{ code: 'TEST 1', mandatory: true},
{ code: 'TEST 2', mandatory: true},
{ code: 'TEST 3', mandatory: false},
{ code: 'TEST 5', mandatory: false},
];

在 html 模板中我有这个循环:

<li class="list-group-item" *ngFor="let document of documents">
   <span>{{document.code}}</span>
</li>

我有一个这样的常量:

const mandatory = true;

我需要遍历文档,只显示必填项为 TRUE 的文档。我知道我可以在 JavaScript 代码中进行过滤,但我需要在 html 模板中进行。

0 个答案:

没有答案
相关问题