javascript - Watch ng-model whilst using minlength? -
i'm trying watch value of ng-model
whilst using minlength
validation. problem model value remains empty/undefined until validation criteria met.
html
<input ng-model="xyz" minlength="8" />
js
$scope.$watch('xyz', function(val) { // either undefined or // string bigger or equal // 8 characters. console.log(val); });
i know substring
element's value, code implemented in directive uses $compile
, ideally i'd prefer watch model value.
any thoughts on how resolve this?
https://docs.angularjs.org/api/ng/directive/ngmodeloptions
allowinvalid: boolean value indicates model can set values did not validate correctly instead of default behavior of setting model undefined.
Comments
Post a Comment