有没有编写可维护、易读的HTML模板的最佳实践,尤其是在Angular中?
我经常有一个附加了多个属性的组件,例如:
<custom-component [type]="myType" (myEvent)="onMyEvent()" *ngIf="enabled" [ngSwitch]="condition"></custom-component>
当属性列表变得很长时,将其拆分成多行,或者甚至按优先级组织它们(结构先于属性指令),是更好呢?
谢谢
发布于 2018-07-18 04:49:37
在本例中,我将遵循Google recommendation并将其格式化为:
<custom-component [type]="myType"
[ngSwitch]="condition"
(myEvent)="onMyEvent()"
*ngIf="enabled"></custom-component>
这里,为了便于阅读,我还对[type]
和[switch]
进行了分组。
https://stackoverflow.com/questions/51389832
复制相似问题