11
我想一個指令有條件地添加到組件(其中au-disabled
,au-accented
,並au-focused
是指令)添加指令:如何有條件地在角2
<template [ngIf]="disabled">
<au-placeholder au-disabled></au-placeholder>
</template>
<template [ngIf]="accented">
<au-placeholder au-accented></au-placeholder>
</template>
<template [ngIf]="focused">
<au-placeholder au-focused></au-placeholder>
</template>
上述方法的工作原理(是有點接受對我來說),因爲(就我而言)條件屬性disabled
,accented
和focused
是相互排斥的 - 我的問題出現在條件屬性不互相排斥的情況下(每個排列要求應用[ngIf]
來應用相應的變形表單):
<!-- all of the prior <template [ngIf]= ... -->
<!-- plus -->
<template [ngIf]="disabled && accented">
<au-placeholder au-disabled au-accented></au-placeholder>
</template>
<template [ngIf]="disabled && accented && focused">
<au-placeholder au-disabled au-accented au-focused></au-placeholder>
</template>
<!-- etc -->
使用下面允許我的代碼能夠以較少的HTML處理組合:
<au-placeholder [au-disabled]="disabled" [au-accented]="accented" [au-focused]="focused"></au-placeholder>
,但呈現的HTML始終都各持真值的指令...該組件必須測試每個指令的真實價值都會得到適當的迴應,但是即使不適用不相關的指令也會更清晰。有一個更好的方法嗎?
OK ......這是什麼'<太子港佔位符[AU-禁用= 「禁用」[AU口音] = 「重音符號」[AU-關注] = 「強調」> au-placeholder>'表格正在做... – Neoheurist