0
我想隱藏img如果路由不活躍。我曾嘗試:Angular2 ngIf不起作用
<div class="sidebar-nav-item dashboard-item" routerLinkActive="active" #rlaDashboardW="routerLinkActive">
<a routerLink="/core/dashboard">
<span class="helper"></span>
<div class="re-full-height icon">
<img class="nav-icon" src="{{ rlaDashboardW.isActive ? './assets/navigation/dashboard-icon-active.svg' : './assets/navigation/dashboard-icon.svg'}}"
/>
</div>
<div class="re-full-height">
<span> Dashboard </span>
</div>
</a>
<div class="separator-container">
<img *ngIf="{{rlaDashboardW.isActive}}" src="./assets/navigation/navigation-separator-wide-active.svg" />
<img src="./assets/navigation/navigation-separator-wide.svg" />
</div>
</div>
但去這個錯誤:http://pastebin.com/TPXZU3BD
,如果我嘗試:
<div class="sidebar-nav-item dashboard-item" routerLinkActive="active" #rlaDashboardW="routerLinkActive">
<a routerLink="/core/dashboard">
<span class="helper"></span>
<div class="re-full-height icon">
<img class="nav-icon" src="{{ rlaDashboardW.isActive ? './assets/navigation/dashboard-icon-active.svg' : './assets/navigation/dashboard-icon.svg'}}"
/>
</div>
<div class="re-full-height">
<span> Dashboard </span>
</div>
</a>
<div class="separator-container">
<img *ngIf="rlaDashboardW.isActive" src="./assets/navigation/navigation-separator-wide-active.svg" />
<img src="./assets/navigation/navigation-separator-wide.svg" />
</div>
</div>
我得到錯誤:http://pastebin.com/wsGLqNx4
注:這兩個片段之間的差異在第一個我使用插值和第二個我直接綁定到模板變量。
NOTE2:我遇到了ngClass類似的問題,所以我相信這是一個全球性的問題 - 將調查並更新
我有App.Module中導入的FormsModule,以及作爲導出的SharedModule(SharedModule導入該模板所在的CoreModule中) ,以及在Core.Module中作爲單獨的導入...此外,這些錯誤是我在運行兩個片段時得到的...如果刪除片段,我不會收到錯誤=>錯誤與代碼:) – mp3por
我認爲在ngIf/ngClass表達式中使用綁定變量時存在問題(我有類似於ngClass的問題) – mp3por
首先,您不需要額外引用變量,所以* ngIf ='yourVar'。然後,TypeError:無法讀取未定義的屬性'toUpperCase'與您當前的代碼無關。 – Sakuto