简体   繁体   English

Angular HTML模板最佳实践

[英]Angular HTML Template Best Practices

Are there best practices for writing maintainable, easy to read HTML templates, specifically in Angular? 是否有最佳实践来编写可维护的,易于阅读的HTML模板,尤其是在Angular中?

I often have a component with multiple attributes attached to it, for example: 我经常有一个带有多个属性的组件,例如:

<custom-component [type]="myType" (myEvent)="onMyEvent()" *ngIf="enabled" [ngSwitch]="condition"></custom-component>

Is it better, when the attribute list becomes long, to split it up into multiple lines, or maybe even organize them by precedence (structural before attribute directives)? 当属性列表变长时,将它分成多行,或者甚至按优先级将它们组织起来(结构在属性指令之前),会更好吗?

Thanks 谢谢

In this case I would follow Google recommendation and format it as: 在这种情况下,我会遵循Google的建议并将其格式设置为:

<custom-component [type]="myType" 
                  [ngSwitch]="condition"
                  (myEvent)="onMyEvent()" 
                  *ngIf="enabled"></custom-component>

Here I also grouped [type] and [switch] for ease of read. 在这里,为了便于阅读,我还对[type][switch]进行了分组。

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

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