简体   繁体   English

Angular 2 CRUD 组件

[英]Angular 2 CRUD Components

I'm getting started with Angular 2 with TypeScript and I'm trying to find the best way of organizing my application.我开始使用带有 TypeScript 的 Angular 2,我正在尝试找到组织我的应用程序的最佳方式。

Imagine that I want to CRUD a product.想象一下,我想 CRUD 一个产品。 Since I want each CRUD operation to have different views should I create a component for each operation?既然我希望每个 CRUD 操作都有不同的视图,我应该为每个操作创建一个组件吗? For example: createProduct.component;例如:createProduct.component; editProduct.component;编辑Product.component; getProduct.component; getProduct.component; etc.;等等。; that all reuse the product class and the product.service in order to make http requests to the server?为了向服务器发出 http 请求,所有这些都重用产品类和 product.service 吗?

I think this makes sense, but I'm not sure there's a better way to do it and since Angular 2 is fairly new, I'm having trouble finding proper documentation for this problem.我认为这是有道理的,但我不确定是否有更好的方法来做到这一点,而且由于 Angular 2 是相当新的,我无法找到针对此问题的适当文档。 Any thoughts?有什么想法吗?

  • Create a /+product folder创建一个/+product文件夹
  • Add all product components (edit/view/create), also include the test(product.spec.ts) files添加所有产品组件(编辑/查看/创建),还包括测试(product.spec.ts)文件
  • Create a /services folder, add the product.service创建一个/services文件夹,添加product.service

您可以在此处找到官方样式指南https://angular.io/docs/ts/latest/guide/style-guide.html

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

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