MOCKSTACKS
EN
Questions And Answers

More Tutorials









Angular ng-model-options


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

1. updateOn: specifies which event should be bound to the input ng-model-options="{ updateOn: 'blur'}" // will update on blur

2. debounce: specifies a delay of some millisecond towards the model update ng-model-options="{'debounce': 500}" // will update the model after 1/2 second

3. 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.

4. 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";}


5. timezone: defines the timezone for the model if the input is of the date or time. types


Conclusion

In this page (written and validated by ) you learned about AngularJS ng-model-options . What's Next? If you are interested in completing AngularJS tutorial, your next topic will be learning about: AngularJS ngCopy.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.