什么可能導致 Angular 不將id屬性添加到我在 DOM 中的組件。
TS:
export class InputComponent extends BaseComponent {
@Input() public id: string = '';
...
}
HTML:
<lib-input
id="{{ vo.id }}-username"
label="Username"
i18n-label
[control]="vo.loginForm.username"
[autofocus]="true"
></lib-input>
DOM:
<lib-input label="Username"
ng-reflect-label="Username"
ng-reflect-id="lib-ui-login-username"
ng-reflect-control="[object Object]"
ng-reflect-autofocus="true">
堆疊閃電戰
uj5u.com熱心網友回復:
字串插值有問題。沒有{{...}}在idDOM 中按預期出現。
我對 Angular 沒有處理它感到非常失望。
編輯:實際上HostBinding是一個很好的解決方法。
export class MyInput {
@Input()
@HostBinding('attr.id')
id: string;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/479903.html
