如何訪問ng-repeat指令範圍之外的條件設置的ng-repeat數據?例如,當有人選擇一個在ng-repeat內生成的單選按鈕時,我想在ng-repeat之外顯示一個div塊。ng-repeat值在ng外部評估 - if
app.js
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.obj = [{
condition: "Question1",
status: "no"
}, {
condition: "Question2",
status: "no"
}];
}
的.html
<tr ng-repeat="o in obj">
<td>{{o.condition}}</td>
<td>
Yes
<input type="radio" ng-model="o.status" value="yes" /> No
<input type="radio" ng-model="o.status" value="no" />
</td>
</tr>
<!-- this will show based on an input event-->
<div ng-if="o.status == 'yes'" class="myClass">
I show up
</div>
http://jsfiddle.net/fergnab/jmb619qg/
你要顯示的附加'div'取決於哪個問題? – miensol
是的,我想通過選擇radio ='yes'來在ng-repeat之外顯示div(或任何元素)。謝謝 – Fergus
你(可)在'obj'中有'o'多個問題。哪個'是'設置應該顯示額外的div?或者,當設置爲'yes'時,'obj'中的每個'o'都應該顯示一個新的div? – miensol