JavaScript array - NaN? AngularJS ngModel

I am trying to understand what the value of ngModel is:

.directive('myDir', function() {
  return {
    require: '?ngModel',
    link: function(scope, elm, attr, ngModel) {
      if (!ngModel)
        return

      console.log(ngModel)
      console.log(ngModel.$modelValue)
    }
  };
})

Although my ngModel is an array, does it register NaN?

What's going on here?

+4
source share
3 answers

$ viewValue and $ modelValue by default Number.NaNis the JavaScript definition for Not - a - Number.

check out github and you will find that

var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 
                                 '$element', '$parse',
'$animate', '$timeout',
    function($scope, $exceptionHandler, $attr, $element, $parse, 
                   $animate, $timeout) 
  {
  this.$viewValue = Number.NaN;
  this.$modelValue = Number.NaN;

Why is this convenience? Because AngularJS is trying to avoid cases like nulland undefined. View values ​​and model values ​​are related and determined by the "domain". What the $ scope service point is to control the modelValue and viewValue parameters.

, AngularJS , Number.NaN

+5

, ngModel, ngModel.$modelValue NaN. ngModel.$modelValue, . .. , ngModel.$modelValue . , ( ) .

:

var s = {
    some: 1,
    big: [ 1, 2, 3 ],
    object: [ "that gets a little drop-down arrow next to it when you log" ]
}
console.log(s);
s.some = "Changed!";

, s.some "Changed!" 1, 1, .

+2

Angular.js, .

. " " ( ) $modelValue: NaN. NaN , console.log(ngModel.$modelValue). , , , NaN.

"i", : " ". , , .

, ngModel - "" . NaN. - , , , $modelValue - .

0

Source: https://habr.com/ru/post/1543604/


All Articles