如何检查AngularJS页面上的每个输入元素,可见或不可见?

时间:2015-08-18 14:40:23

标签: html angularjs

例如,我有一个页面,其中包含一些指令形式。我想将页面上的每个输入元素存储到一个变量中,但其中一些元素隐藏在ng-if后面。

如果这些元素目前在视图中是否可见,我该如何获取这些元素?目前我正在使用

var selects = document.getElementsByTagName('select');

这是在与下面的templateHTML相对应的指令上运行的:

<div>
  <label>Are you planning to attend a commencement ceremony at the Athens Campus? </label>
  <select id="ceremony" name="ceremony" ng-model="gradCeremony" ng-options="option.value as option.name for option in options" required>
  <option value="">Selection Required</option>
  </select>
</div>

<div>
  <label class="control-label" for="regional-ceremony">Are you planning to attend a recognition ceremony at one of the regional campuses?</label>
  <select id="regional-ceremony" ng-model="regionalCeremony" ng-options="option.value as option.name for option in options">
  </select>
</div>

<!-- This one is hidden by default -->
<div ng-if="regionalCeremony">
  <label>Please indicate the regional campus</label>
  <select id="regional-campus-ceremony" ng-model="regionalCeremonyCampus" ng-options="c.code as c.name for c in campuses" required>
    <option value="">Selection Required</option>
  </select>
</div>

如您所见,最后一个选项隐藏在ng-if后面。它并没有像我希望的那样在输入数组中被选中。

在html中使用此代码调用此代码:

<form name="Form" commencement application="application" campuses="campuses" submitting="submitting"></form>

0 个答案:

没有答案