2016-08-03 69 views
0

在我的應用程序中,我想要顯示基於活動鏈接的內容,例如:如果鏈接是「新」,那麼「abc」,如果鏈接是「查看」,則應顯示「xyz」。爲此,我爲我的應用程序使用了以下代碼。

<li><a href="#/new" ng-class="{active: $route.current.activetab == 'new'}">New</a></li> 
<li><a href="#/view" ng-class="{active: $route.current.activetab == 'view'}">View</a></li> 

<span class="white-text" ng-show="{{ $route.current.activetab === 'new' }}">new</span> 
<span class="white-text" ng-show="{{ $route.current.activetab === 'view' }}">view</span> 
+0

'ng-show'應該沒有插值指令,就像'ng-show =「$ route.current.activetab ==='new'」'一樣,還要確保'$ route'已經暴露給' $ scope'就像控制器中的$ scope。$ route = $ route' –

回答

3

當您使用{{}}時,這些值將被內插,即標記將被替換爲表達式的結果。 ngShow僅期望的表達,因此就使用功能,因爲它是,它會工作:

<span class="white-text" ng-show="$route.current.activetab === 'new' ">new</span> 
<span class="white-text" ng-show="$route.current.activetab === 'view' ">view</span> 

一般情況下,你只需要{{ }}時,應顯示你的表達/內容。

希望這個作品!

相關問題