我有一堆包含输入和按钮的表行,即。如果该值与所定义的要求不匹配,我希望在行的输入右侧有一个Popover显示。该按钮也将被禁用,直到输入值正确。Popover的问题AngularJS
相关HTML:
<div class="row col-md-4">
<table ng-controller="TestController" style="width: 100%">
<tr ng-repeat="element in model.InvoiceNumbers">
<td><input ng-model="element.id"
popover="Invoice must match ##-####!"
popover-placement="right"
popover-trigger="{{ { false: 'manual', true: 'blur'}[!isValidInvoice(element.id)] }}"
popover-title="{{element.id}}"/></td>
<td>{{element.id}}</td>
<td><button ng-disabled="!isValidInvoice(element.id)">Approve</button></td>
</tr>
</table>
</div>
相关的JavaScript:
app.controller("TestController", function ($scope) {
$scope.model = {
InvoiceNumbers : [
{ id: '12-1234' },
{ id: '12-1235' },
{ id: '1234567' },
{ id: '1' },
{ id: '' }],
};
$scope.isValidInvoice = function (invoice) {
if (invoice == null) return false;
if (invoice.length != 7) return false;
if (invoice.search('[0-9]{2}-[0-9]{4}') == -1) return false;
return true;
};
});
按钮大干快上我的本地解决方案正确禁用。但是,我无法让Popover工作。它的行为就好像其范围内的模型没有得到更新。所以,我在这里查看了几个链接(尽管大多数都是从2013年开始的,所以我想可能会有一些变化),并且他们的问题似乎可以通过移除原始绑定来解决。这并没有解决任何问题。我在从Popover调用的函数中添加了一些console.log()行,并且每次都从模型中获取正确的值。我还为Popover添加了一个标题,以表明它从模型中看到了正确的价值。在看到日志显示它应该正常工作后,我已经用完了想法。
问题是element.id没有在触发器内动态更新(它保持它的初始值,不像popover-title更新模型)。有什么我做错了吗?
另外,我一直只与角一天工作,所以如果你们都有更好的方法来完成这一任何建议,我愿意提供建议。
Plunker:http://plnkr.co/edit/tiooSxSDgzXhbmIty3Kc?p=preview
感谢