我有一些奇怪的行爲正在用ng-show進行。我有一個post
,title
和link
屬性。鏈接可能存在也可能不存在。如果是這樣,我想將標題顯示爲鏈接,否則只顯示標題。ng顯示奇怪的行爲發生了什麼事?
(行:<a href="{{post.link}}"> {{post.link}}</a>
是測試代碼,而只是在那裏說明{{post.link}}
呢,其實,絕對包含的值)
<a ng-show="{{post.link}}" href="{{post.link}}">
{{post.title}}
</a>
<a href="{{post.link}}"> {{post.link}}</a>
給我:
所以,你可以看起來像{{post.link}}
存在,可以訪問和填充......但仍然以某種方式評估爲假,只要ng-show是關心的,並且不顯示。我能看到的只是測試代碼的結果。
鑑於,如果我評估true
,甚至{{post.title}}
,那麼ng顯示工作。
我很困惑 - 我錯過了什麼?
<a ng-show="true" href="{{post.link}}">
{{post.title}}
</a>
<a href="{{post.link}}"> {{post.link}}</a>
或
<a ng-show="{{post.title}}" href="{{post.link}}">
{{post.title}}
</a>
<a href="{{post.link}}"> {{post.link}}</a>
給我:
以及下面,使用ng-href請參閱https://docs.angularjs.org/api/ng/directive/ngHref –