javascript - 你会如何在 Angular 6 中设计这个组件?
问题描述
我有一个关于正确组件设计的相当基本的问题。
我创建了一个基本的手风琴组件,我用它来显示标题和描述。如果单击标题,则显示或隐藏(切换)说明。
@Input() title: String;
@Input() description: String;
目前我将模板中的标题和描述作为道具传递。
<div *ngFor="let project of individualProjects">
<app-accordion-item
[title]="project.title"
[description]="project.description"
[chips]="project.tags">
</app-accordion-item>
</div>
手风琴模板
<div class="accordion-description" *ngIf="opened">
{{ description }}
</div>
使用这种结构,渲染一个没有任何列表项或新行的简单段落不是问题。
但是,假设 individualProjects 数组的一项如下:
{
title: "Project title",
description: `
The overall project involved the following:
Project detail 1
Project detail 2
Project detail 3
..
Some more text about project`,
tags: ["tag"]
},
...
Some more text here
我希望能够将“项目详细信息 x”项目呈现为列表元素,这表明我在这里需要不同的结构。我意识到我可能会遇到与此问题有关的许多不同情况,这需要我更新此结构。
这是使用ng-content的合理点吗?否则,你会建议我如何处理这个问题?
谢谢
解决方案
推荐阅读
- null - Unity 3D 警告 CS0414:现场
已分配,但从未使用过它的值 - python-3.x - 为什么我的 Python 3 代码不起作用?(类和对象)
- excel - Excel - 如何在不使用数组公式和辅助列的情况下将唯一值从一列提取到另一列?
- java - Spring Boot Embedded Undertow Server : java.io.IOException: UT000128: Remote peer closed connection before all data can be read
- java - axios 加载数据的速度不够快
- c# - Entity Framework 6 删除更新请求中不存在的所有行
- python - HTTPConnectionPool(host='xxxx', port=y):读取超时。(读取超时=无)在 nginx 服务器上?
- javascript - 在分页中过滤文本字段 Jquery
- html - 外部css文件在压缩文件夹中不起作用
- python - 如何更优雅地编写这些嵌套的 if 语句?