我有一堆包含輸入和按鈕的錶行,即。如果該值與所定義的要求不匹配,我希望在行的輸入右側有一個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
感謝