[英]How to check in real time if a input field matches another variable with angular.js
我有一個ng-repeat,它遍歷一個對象並顯示字符串和輸入字段的列表,例如下面的示例。 我需要為這些輸入字段設置實時驗證。 輸入字段應等於條形碼字符串。 如果用戶輸入的字符串與條形碼字符串不相等,則輸入的角度不等於角度,應提示用戶必須與條形碼字符串相等,並清除輸入字段。 角度可以嗎? 我已經用jQuery完成了類似的任務。我可以結合使用jQuery和Angular來完成此驗證嗎? 我是angular.js的新手,因此非常感謝您的幫助。
HTML:
<div ng-repeat="(index, val) in barcodes.barcodes track by $index">
<div class="form-group row" ng-show="barcodes.barcodes[index]">
<label class="col-sm-3 form-control-label" style="margin-top: 5px"> {{ barcodes.adaptors[$index] }} </label>
<label class="col-sm-3 form-control-label" style="margin-top: 5px"> {{ barcodes.barcodes[index] }} </label>
<div class="col-sm-6">
<input type="email" class="form-control" placeholder="Barcode">
</div>
</div>
</div>
示例欄對象:
var bars = {
"adaptors": ["506-704", "505-703", "503-702", "508-701", "507-705", "502-706", "504-707", "501-708"],
"barcodes": ["11-11-1111","11-11-2222","11-11-3333","11-11-4444","X","X","X","X"];
}
如果您想要實時...觀察者可能就是您想要的。 但是觀察者效率不高。
最好是使用ng-change指令。 這樣,用戶每次鍵入時,都會觸發傳遞給ng-change指令的函數。 這可以讓您處理函數內部的邏輯並根據需要進行響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.