Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性是否在Angular中使用子组件?_Angular_Angular6_Angular8 - Fatal编程技术网

属性是否在Angular中使用子组件?

属性是否在Angular中使用子组件?,angular,angular6,angular8,Angular,Angular6,Angular8,如何决定何时在父对象内使用子对象角度组件 它应该是一个实体,例如“课程列表”和“添加课程” 我试着得到什么时候应该使用子组件,什么时候存在真正的父子关系 假设我们的产品卡中有按钮: <app-product-card> <!-- Product information here --> <app-product-buttons></app-product-buttons> </app-product-card> 或内部

如何决定何时在父对象内使用子对象角度组件

它应该是一个实体,例如“课程列表”和“添加课程”

我试着得到什么时候应该使用子组件,什么时候存在真正的父子关系

假设我们的产品卡中有按钮:

<app-product-card>
    <!-- Product information here -->
    <app-product-buttons></app-product-buttons>
</app-product-card>
或内部作为子按钮组件:

  <app-product-card>
        <!-- Product information here -->
        <app-product-buttons>
               <app-users-producst-buy [product]="product"></app-users-producst-buy>
        </app-product-buttons>
    </app-product-card>

如何对这种情况做出正确的决定?
还是应该使用动态组件?

根据我使用Angular framework的经验,这个决定并不总是像您所说的那么容易

此外,您可以应用此类规则:

1) 模块化:当我要设计的子组件将出现在项目中的多个位置时,我总是使用子组件

2) 可维护性:越简单,越容易维护。当一个组件趋向于巨大时,您可以识别几个子组件,让我们将其拆分

3) DRY(不要重复自己):考虑小的、专门的组件(当然,不要过度考虑)可能是保持小但功能非常强大的代码库的关键


我希望这些观点能帮助你做出决定

我想说这是一个自以为是的问题,这取决于你的设置和要求。子组件是否需要与其父组件通信?它在其他地方可重用吗?不,子级不应仅与父级通信单向数据流,父级->子级。没有任何回调到父级。我也可以从另一个地方调用子组件。是的,它在其他地方也是可重用的,我只需将父数据传递给子组件。这取决于您,先生。如果看不到这些组件的实际功能,很难说清楚,但无论什么对您的案例有效。
  <app-product-card>
        <!-- Product information here -->
        <app-product-buttons>
               <app-users-producst-buy [product]="product"></app-users-producst-buy>
        </app-product-buttons>
    </app-product-card>