我有以下代碼:Angular2動態IMG SRC
<a routerLink="/dashboard" routerLinkActive="active" #rla="routerLinkActive">
<img src="/assets/navigation/dashboard-icon-active.svg" />
<template [ngIf]="!isSmallSidebar">
Dashboard
</template>
</a>
運行我的應用我看到的圖像正確顯示。不過,如果當前路線處於活動狀態,我希望圖像更改。所以我做:
<a routerLink="/dashboard" routerLinkActive="active" #rla="routerLinkActive">
<!-- <img
id="re-nav-dashboard-img"
src={{ rla.isActive ? './assets/navigation/dashboard-icon-active.svg' : './assets/navigation/dashboard-icon.svg' }} /> -->
<template [ngIf]="!isSmallSidebar">
Dashboard
</template>
</a>
什麼我做錯了或這是一個錯誤?
如果綁定的值是一個字符串,它們是等價的。 –
我的方法有什麼不同? – mp3por
@GünterZöchbauer我不知道,但在閱讀https://angular.io/docs/ts/latest/guide/template-syntax.html#interpolation後,我必須同意:) –