简体   繁体   English

有没有办法让我的组件在 angular 中完全可重用?

[英]Is there a way to make my components fully reusable in angular?

I created a simple component to display a list of buttons using the ngFor directive.我创建了一个简单的组件来使用 ngFor 指令显示按钮列表。

Here is a simplified version of what the component looks like : https://stackblitz.com/edit/angular-eezqjv这是组件外观的简化版本: https : //stackblitz.com/edit/angular-eezqjv

The data will be eventually fetched from an api through a service component and I'm wondering if there is a way to reuse this list component I created with different data.数据最终将通过服务组件从 api 获取,我想知道是否有办法重用我用不同数据创建的这个列表组件。

this post helped me make my component reusable Angular 4 - make component more reusable这篇文章帮助我使我的组件可重用Angular 4 - 使组件更可重用

I placed the @Input() decorator followed by only instantiating the variable of type Tile (the interface I created) in the .ts file and I moved the data from there to the file that is using the component.我放置了 @Input() 装饰器,然后仅在 .ts 文件中实例化 Tile 类型的变量(我创建的接口),然后将数据从那里移动到使用该组件的文件中。 When I placed my custom component in the html template file, I bound the data using the square brackets notation from the component.ts to the component.html当我将自定义组件放在 html 模板文件中时,我使用方括号表示法将数据从 component.ts 绑定到 component.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM