【发布时间】:2016-09-09 16:03:40
【问题描述】:
我有一个这样的 javascript 数组:
$scope.quantityMachines = [
{ 'snippet' : 'One' },
{ 'snippet' : 'Two' },
{ 'snippet' : 'Three or more',
'extraField' : true },
{ 'snippet' : 'Not sure, need advice' }
];
然后我有一个由 Angular JS 使用数组生成的单选按钮列表:
<ul>
<li ng-repeat="quantity in quantityMachines">
<input type="radio" id="quantityMachines{{$index}}" name="quantityMachines" value="{{quantity.snippet}}" ng-model="howMany" />
<label for="quantityMachines{{$index}}">{{quantity.snippet}}</label>
</li>
</ul>
这行得通。在数组中有一个extraField,其中一个索引中的值为true。当检查带有 extraField设置的广播按钮时,我需要Angular显示一个额外的输入字段。该数组可能会更改为具有多个具有extraField 值的索引。
所以额外的字段看起来像这样。
<input type="text" ng-model="extraInfo" ng-show="howMany" />
除了知道使用ng-show 之外,我不确定执行此操作的正确方法是什么。上面的例子当然什么也没做。
【问题讨论】:
标签: javascript html angularjs ng-show