为什么 ng-show 和 ng-hide 不能与 angular 中的 $route 一起使用?

Why ng-show and ng-hide don't work with $route in angular?

在我的应用程序中,我想显示基于活动 link 的内容,示例:如果 link 是 "new",则 "abc",如果 [=18] =] 是 "view" 那么应该显示 "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>

当您使用 {{}} 时,值是内插的,即标记被替换为表达式的结果。 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>

一般来说,当您的表情/内容应该显示时,您只需要 {{ }}

希望这有效!