对于每个“条目中的条目”,我都有一个将 ng-show 切换为 true 的按钮,并显示有关条目的详细信息。目前,此代码将每个条目切换为 ng-show=true。我希望每个按钮仅切换其所在条目的详细信息。
我的观点:
<h1>Listing Projects</h1>
<ul class="unstyled">
<li ng-repeat="entry in entries" ng-init="entryClass=isClass(entry.isProject)">
<ul class="unstyled">
<li>
<div class="alert" ng-class="entryClass">
<h3>{{entry.title}}</h3>
<button ng-click="toggleShow()">Details</button>
<div style="background-color:#000000; min-width:100px; min-height:100px;" ng-show="showThis">
</div>
</div>
</li>
</ul>
</li>
</ul>
AngularJS:
app = angular.module("Resume", ["ngResource"])
app.factory "Entry", ["$resource", ($resource) ->
$resource("/entries")
]
@EntryCtrl = ["$scope", "Entry", ($scope, Entry) ->
$scope.entries = Entry.query()
$scope.showThis = false
$scope.isClass = (isProject) ->
if isProject == true
$scope.myVar = "project alert-info"
else
$scope.myVar = "tech alert-success"
$scope.toggleShow = ->
if $scope.showThis == false
$scope.showThis = true
else
$scope.showThis = false
]