我有一個嵌套列表來顯示3個級別的註釋和回覆。我通過顯示和隱藏兩個日期元素中的一個來切換從前一時間到實際點擊的日期。這適用於使用ng-click="$parent.swapDate=!$parent.swapDate"
的每個級別,但不會影響其他級別。從嵌套的AngularJS或Ionic指令中切換布爾變量
如何將切換應用於結構的所有級別,如下所示(簡化)?
<ion-content>
<div class="list">
<div class="item" ng-repeat="comment in comments">
<span am-time-ago="comment.date | amUtc | amLocal"
ng-click="$parent.swapDate=!$parent.swapDate"
ng-hide="$parent.swapDate">
</span>
<span ng-click="$parent.swapDate=!$parent.swapDate"
ng-show="$parent.swapDate">
{{comment.date | amDateFormat: 'D MMMM YYYY @ h:mma'}}
</span>
<div class="list">
<div class="item" ng-repeat="comment in comments">
<span am-time-ago="comment.date | amUtc | amLocal"
ng-click="$parent.swapDate=!$parent.swapDate"
ng-hide="$parent.swapDate">
</span>
<span ng-click="$parent.swapDate=!$parent.swapDate"
ng-show="$parent.swapDate">
{{comment.date | amDateFormat: 'D MMMM YYYY @ h:mma'}}
</span>
</div>
</div>
</div>
</div>
</ion-content>
我寧願不使用全局變量或服務這樣一個簡單的事情。謝謝。
我懷疑你指的是使用對象而不是基元('點'問題)。請詳細說明(並使用代碼標記以提高可讀性)。 – isherwood