简体   繁体   English

Angular 可重复使用的crud组件

[英]Angular reusable crud component

I got the mission to build 10 cruds in angular, but I want to create a reusable component for it.我的任务是在 angular 中构建 10 个 crud,但我想为它创建一个可重用的组件。 I've been thinking if I could separate the components between list and form like below:我一直在考虑是否可以将列表和表单之间的组件分开,如下所示:

Eg:例如:

在此处输入图像描述

在此处输入图像描述

4 crud's will use live data edition and won't need the form part. 4 crud 将使用实时数据编辑并且不需要表单部分。 In the case with form I will share the data with a service between then.在表单的情况下,我将在此期间与服务共享数据。

With this in mind I'm thinking to build a generic component to wrap that behaviour, but in same time, afraid to create a kind of god component hard to maintain and reuse考虑到这一点,我正在考虑构建一个通用组件来包装该行为,但同时又害怕创建一种难以维护和重用的上帝组件

Have you guys ever did some similar task?你们有没有做过类似的任务? Where can I find a good start point for me to base or is there some project where I can get a example?我在哪里可以找到一个好的起点,或者是否有一些项目可以让我获得一个例子?

I'm not sure the extent that you have to accomplish (be wary of over-engineering), but if you needed to, you could always base a lot of your needs on inputs and make it pretty re-usable.我不确定你必须完成的程度(警惕过度设计),但如果你需要,你总是可以将你的很多需求建立在输入上,并使其非常可重用。

I used this Dynamic forms site to give me a start on how to create forms from a payload, which may be what you would lean towards.我使用这个动态 forms站点让我开始了解如何从有效负载创建 forms,这可能是您倾向于的。 Either way, you can always start off by fulfilling a need of 1 crud and see if you can make it generic through @Input() elements and see where that gets you.无论哪种方式,您总是可以从满足 1 个 crud 的需求开始,看看您是否可以通过 @Input() 元素使其通用,然后看看它会带给您什么。 Good luck!祝你好运!

Happy coding快乐编码

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

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