2017-06-23 31 views
0

如果我有一个服务返回多个数据点,并且这些服务需要在多个html部分中显示(在下面三种情况下)。什么是组织&架构师的最佳方式?Angular 2最佳实践 - 哪一个HTML作品被限定为组件

请注意,此处的区域和属性始终显示在一起。

有三种选择,我有点困惑之间的第一和第二,哪一个选择。

  1. 创建三个组件:TemplateComponent,SectionsComponent & PropertyComponent?
  2. 创建两个组件:一个用于模板的组件和另一个用于区段和属性的组件?
  3. 创建一个组件:所有三个部分的一个组件。

我们在CLI中使用Angular〜2.0。

样品服务响应

Template_A 
    - Section 1 
     - Property a 
     - Property b 
    - Section 2 
     - Property a 
     - Property b 
Template_B 
    - Section 1 
     - Property a 
     - Property b 
    - Section 2 
     - Property a 
     - Property b 

样品UI enter image description here

回答

0

您可以创建一个基本组件,并建立尽可能多的子组件所需并将数据传递到子组件。

在你的情况下,你将创建三个组件。

  1. TemplateComponent
  2. SectionsComponent
  3. PropertyComponent

    • SectionsComponentTemplateComponent的一个子组件,其 将接收切片数据作为输入。
    • PropertyComponent将是孩子SectionsComponent将接收属性数据作为输入。

参考https://angular.io/guide/component-interaction获取更多信息。