ng-model-options
allows to change the default behavior of ng-model
, this directive allows to register events that will fire when the ng-model is updated and to attach a debounce effect.
This directive accepts an expression that will evaluate to a definition object or a reference to a scope value.
Example:
<input type="text" ng-model="myValue" ng-model-options="{'debounce': 500}">
The above example will attach a debounce effect of 500 milliseconds on myValue
, which will cause the model to update 500 ms after the user finished typing over the input
(that is, when the myValue
finished updating).
Available object properties
updateOn
: specifies which event should be bound to the input
ng-model-options="{ updateOn: 'blur'}" // will update on blur
debounce
: specifies a delay of some millisecond towards the model update
ng-model-options="{'debounce': 500}" // will update the model after 1/2 second
allowInvalid
: a boolean flag allowing for an invalid value to the model, circumventing default form validation, by default these values would be treated as undefined
.
getterSetter
: a boolean flag indicating if to treat the ng-model
as a getter/setter function instead of a plain model value. The function will then run and return the model value.
Example:
<input type="text" ng-model="myFunc" ng-model-options="{'getterSetter': true}">
$scope.myFunc = function() {return "value";}
timezone
: defines the timezone for the model if the input is of the date
or time
. types