angular - 如何定义哪个组件负责?
问题描述
我有以下组件的嵌套结构:
<app-orders>
<app-orders-list><div *ngFor="let order of orders"></div></app-orders-list>
<app-pagination></app-pagination>
<app-pagination-showby></app-pagination-showby>
</app-orders>
我对这种结构没有信心,因此问题是:
- 如果
app-orders-list
有分页,应该在<app-pagination></app-pagination>
里面? - 如果
<app-pagination></app-pagination>
取决于showBy
组件的输出参数<app-pagination-showby></app-pagination-showby>
- 它应该放在里面<app-pagination></app-pagination>
吗?
我有一点疑惑...
解决方案
app-pagination
最好独立于app-orders-list
. 通过这种方式,您可以使用app-pagination
不同的视图,而不仅仅是app-orders-list
. 这是一个使用 ng-bootstrap 分页来获得灵感的示例。
关于列表,可能的好设计:
// the word `list` implies that component would accept items to be processed
<app-orders-list [items]='orders">
// if there is a need for item template flexibility, you can make it adjustable
<ng-template itemTemplateDirective></ng-template>
</app-orders-list>
// if you iterate all items and use a component to display item than it is a `list-item`
<app-orders-list-item *ngFor="let order of orders"></div></app-orders-list-item>
推荐阅读
- java - JPA - 如何将 2 个@ManyToOne 映射到同一个父实体
- javascript - JavaScript 更改全局变量
- python - 如何从 Dataframe 对象字段中提取日期值
- c++ - 尝试访问私有多维数组时,程序在编译后卡住
- ansible - 将不同的 SSH 密钥分配给一个清单中的不同主机
- magento - magento 升级后未应用补丁
- python - psycopg2.sql 使用 sql.Identifier 插入变量类型导致类型“整数”不存在
- .htaccess - .htaccess RewriteRule 导致 ERR_TOO_MANY_REDIRECTS 错误
- python - Beautifulsoup 中不显示数字
- python - 最合适的节点-服务器通信设计