我有两个组件(品牌,产品)与分页和搜索。所以,我想创建重用分页器。此分页器组件接收
@Input() currentPage: number;
@Input() totalPage: number;
现在,我有(3:当前,6:总计)
1, 2, [3], 4, 5, 6
当更改页时,它从父组件调用函数,如
this.getAllProduct(currentPage, totalPage);
但是当我使用分页搜索时,在品牌(产品)组件中的功能搜索看起来就像
searchBrand(name);
或
searchProduct(name, sku, brand, category, price, ....);
如何将此函数传递给子组件(分页器),当我单击page时,它将调用这些函数
发布于 2020-04-24 03:56:24
角有这个文档页的例子和解释如何使您的组件交互。彻底阅读它,它将为您提供所需的所有工具:构件相互作用。
要回答这一具体问题:
- With `@Input` you can listen for changes in the child by implementing the [`ngOnChanges`](https://angular.io/api/core/OnChanges) method.
- With `@ViewChild` you can invoke a child's method directly from the parent. This is for more advanced uses, so I doubt you want this for this case.
@Output
。对于更高级的用例,可以使用服务双向地通信父级和子级。
https://stackoverflow.com/questions/61400736
复制相似问题