angularjs - Difference between modelValue and viewValue -
With a custom command, a validation function is added to validate the integer input
< Code> var INTEGER_REGEXP = / ^ \ -? \ D + $ / / App.directive ('integer', function) (return {required: 'ngmodel', link: function (scope, elm, attrs, ctrl) {ctrl. $ Validators.integer = function (modelValue, viewValue } {If (ctrl $ IsEmpty (modelValue)) {// Write a blank model for valid return;} (INTEGER_REGEXP.test (viewValue)) {// This valid return is true;} // This invalid return is false ;};}};});
Each function in the $ validators object receives the modelValue and viewValue.
What is the difference between ModelValue and viewValue?
$ formatter
s and $ parser in your code s ViewView is a value that uses the rendering command to attract itself, the model is the value that is stored in the scope, once the value of the
$ parser
The list is used. If you change the value in the radius, then ngmodel will run that value through its $ formatters
, which is then read as a visual value by the presentation instructions.
Often viewValue string that is displayed in an input element, while the model value is the value that is written in the target format (for example, the date object in a datapikar directive)
Comments
Post a Comment