我在一个更大的 Rails 项目中有一个 Angular 模块。我是 Angular 的新手,如果可以的话,希望避免使用 jQuery(但在整个 Rails 项目中都使用它,并且如果需要的话可以使用它)。我想要做的是,如果结束时间为 ""
,则隐藏一个复选框,如果结束时间中有一个值,则显示一个复选框。不幸的是,如果结束时间是""
,我无法隐藏它。请参阅:
您可以在下面看到我的 HTML 代码:
<div class="control-group span8">
<h4 class="pull-left"><strong>Active Hours (UTC):</strong></h4>
</div>
<div class="control-group span1">
<label class="control-label label-unstyled font-size-14" for="inputStartTime">Start Time</label>
<div class="controls">
<select ng-model="geoRegion.start_time" id="inputStartTime" class="input-small" ng-options="thisHour.value as thisHour.name for thisHour in hours" value="{{geoRegion.start_time}}"></select>
</div>
</div>
<div class="control-group span1">
<label class="control-label label-unstyled font-size-14" for="inputEndTime">End Time</label>
<div class="controls">
<select ng-model="geoRegion.end_time" id="inputEndTime" class="input-small" ng-options="thisHour.value as thisHour.name for thisHour in hours" value="{{geoRegion.end_time}}"></select>
</div>
</div>
<div class="control-group span8">
<div ng-show="clearGeoSegment(geoRegion.end_time)"><label class="inline checkbox label-unstyled font-size-14"><input type="checkbox" id="clearGeoSegment" ng-model="geoRegion.clear_segment">Clear Geo Segment at end of active time period.</label></div>
</div>
<div class="control-group span8">
<p id="broadcast-notice" class="pull-left font-size-14"><strong>Note:</strong> If active hours is blank, the Geo Segment is always active.</p>
</div>
我的 Controller 代码(是的,我使用了 jQuery。但请提出其他建议!):
$scope.clearGeoSegment = (endTime) ->
if endTime is ''
$('#clearGeoSegment').hide()
else
$('#clearGeoSegment').show()
任何帮助将不胜感激!
最佳答案
所以你不需要用jquery进行隐藏/显示。您只需绑定(bind)到一个表达式,当复选框应该可见时,该表达式将为真。在这种情况下,它应该很简单:
<div ng-show="geoRegion.end_time">
您可以完全删除 clearGeoSegment
函数。
关于javascript - Angular JS : ngShow isn't binding my change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24666573/