AngularJS: ng-show / ng-hide not working with `{{ }}` interpolation

問題:

I am trying to show / hide some HTML using the ng-show and ng-hide functions provided by AngularJS . 我試圖使用AngularJS提供的ng-showng-hide函數顯示/隱藏一些HTML。

According to the documentation, the respective usage for these functions are as follows: 根據文檔,這些功能的各自用法如下:

ngHide – {expression} - If the expression truthy then the element is shown or hidden respectively. ngHide – {表達式}-如果表達式爲true,則分別顯示或隱藏該元素。 ngShow – {expression} - If the expression is truthy then the element is shown or hidden respectively. ngShow – {表達式}-如果表達式爲真,則分別顯示或隱藏該元素。

This works for the following usecase: 這適用於以下用例:

<p ng-hide="true">I'm hidden</p>
<p ng-show="true">I'm shown</p>

However, should we use a parameter from an object as the expression then the ng-hide and ng-show are given the correct true / false value but the values are not treated as a boolean so always return false : 但是,如果我們使用對象中的參數作爲表達式,則ng-hideng-show會獲得正確的true / false值,但這些值不會被視爲布爾值,因此始終返回false

Source 資源

<p ng-hide="{{foo.bar}}">I could be shown, or I could be hidden</p>
<p ng-show="{{foo.bar}}">I could be shown, or I could be hidden</p>

Result 結果

<p ng-hide="true">I should be hidden but I'm actually shown</p>
<p ng-show="true">I should be shown but I'm actually hidden</p>

This is either a bug or I am not doing this correctly. 這是一個錯誤,或者我沒有正確執行此操作。

I cannot find any relative information on referencing object parameters as expressions so I was hoping anyone with a better understanding of AngularJS might be able to help me out? 我找不到將對象參數作爲表達式引用的任何相關信息,所以我希望對AngularJS有更好理解的任何人都可以對我有所幫助?


解決方案:

參考一: https://en.stackoom.com/question/qrjx
參考二: https://stackoom.com/question/qrjx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章