我正在学习网络编程和 AngularJS。我的 HTML 文件中有很多冗余代码,但我不知道如何删除它们。
文件:
<select id="selectSearch" ng-model="searchValue">
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
...
<tr>
<td></td>
<td colspan="3">Class</td>
<td x-ng-if="searchValue >= 1">{{ getClass(studentYear) }}</td>
<td x-ng-if="searchValue >= 2">{{ getClass(studentYear+1) }}</td>
<td x-ng-if="searchValue >= 3">{{ getClass(studentYear+2) }}</td>
<td x-ng-if="searchValue >= 4">{{ getClass(studentYear+3) }}</td>
<td x-ng-if="searchValue >= 5">{{ getClass(studentYear+4) }}</td>
<td x-ng-if="searchValue >= 6">{{ getClass(studentYear+5) }}</td>
<td x-ng-if="searchValue >= 7">{{ getClass(studentYear+6) }}</td>
</tr>
<tr>
<td></td>
<td colspan="3">Grades</td>
<td x-ng-if="searchValue >= 1">{{ getGrades(studentYear) }}</td>
<td x-ng-if="searchValue >= 2">{{ getGrades(studentYear+1) }}</td>
<td x-ng-if="searchValue >= 3">{{ getGrades(studentYear+2) }}</td>
<td x-ng-if="searchValue >= 4">{{ getGrades(studentYear+3) }}</td>
<td x-ng-if="searchValue >= 5">{{ getGrades(studentYear+4) }}</td>
<td x-ng-if="searchValue >= 6">{{ getGrades(studentYear+5) }}</td>
<td x-ng-if="searchValue >= 7">{{ getGrades(studentYear+6) }}</td>
</tr>
<tr>
<td></td>
<td colspan="3">Status</td>
<td x-ng-if="searchValue >= 1">{{ getStatus(studentYear) }}</td>
<td x-ng-if="searchValue >= 2">{{ getStatus(studentYear+1) }}</td>
<td x-ng-if="searchValue >= 3">{{ getStatus(studentYear+2) }}</td>
<td x-ng-if="searchValue >= 4">{{ getStatus(studentYear+3) }}</td>
<td x-ng-if="searchValue >= 5">{{ getStatus(studentYear+4) }}</td>
<td x-ng-if="searchValue >= 6">{{ getStatus(studentYear+5) }}</td>
<td x-ng-if="searchValue >= 7">{{ getStatus(studentYear+6) }}</td>
</tr>
...
我想我需要使用ng-repeat && ng-init,但我不知道在这种情况下如何使用它们..