【发布时间】:2016-07-17 14:10:42
【问题描述】:
我有一个使用模板弹出 Angular UI Bootstrap 弹出框的按钮。
您可以在this pen查看它
弹出框模板是一个表格,表格包含一系列带有 ng-models 的文本字段:
<script type="text/ng-template" id="filterPopoverTemplate.html">
<div class="filters">
<form>
<table>
<tbody>
<tr>
<td><input type="text" size="5" ng-model="filterHsCodeRestricted"></td>
<td>HS Code Restricted</td>
</tr>
<tr>
<td><input type="text" size="5" ng-model="filterHsCode10"></td>
<td>HS Code 10</td>
</tr>
<tr>
<td><input type="text" size="5" ng-model="filterCOD"></td>
<td>COD</td>
</tr>
</tbody>
</table>
<div class="filter-buttons">
<button tabindex="0" class="btn btn-default btn-xs" ng-click="applyFilters()">Apply</button>
<button class="btn btn-default btn-xs" ng-click="resetFilters()">Reset</button>
</div>
</form>
</div>
</script>
我有一个“重置”按钮,它调用一个函数,我想将所有 ng-model 重置为空字符串:
$scope.resetFilters = function () {
$scope.filterHsCodeRestricted = '';
$scope.filterHsCode10 = '';
$scope.filterCOD = '';
};
但是,如果我在字段中输入内容并单击“重置”,则模型不会被设置为空字符串。我在其他地方做过这个并且它可以工作,只是不在弹出模板内,所以我认为它与弹出框 ng-template 中的字段有关。我如何“访问”那些?
【问题讨论】:
-
如果我错了,请纠正我,但不应该将变量绑定到模型以便能够使用
ng-model?像这样mymodelname.filterHsCodeRestricted -
我已经按照我在应用程序中的其他位置使用它的方式使用它。 AFAIK 您只需要在 $scope 上声明一个变量即可使用 ng-model。这是 Angular 1.4.1。
-
总是总是使用
ng-model中的对象。绑定到原语将在子范围内中断 -
这 3 分钟的视频非常值得花时间去理解 issue egghead.io/lessons/angularjs-the-dot
标签: javascript angularjs angular-ui-bootstrap