JavaScript数组是喃? AngularJS ngModel [英] JavaScript array is NaN? AngularJS ngModel

查看:390
本文介绍了JavaScript数组是喃? AngularJS ngModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看到的内容的ngModel的值是:

I'm trying to see what the value of an ngModel is:

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

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

虽然我ngModel是它记录NaN的数组?

Even though my ngModel is an array it logs NaN?

推荐答案

$ viewValue $ modelValue 默认为 Number.NaN - JavaScript的定义不 - 一个 - 号

$viewValue and $modelValue default to Number.NaN -- JavaScript Definition for Not - a - Number.

检查 Github上 ,你会发现

check Github and you 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;

这是为什么convienient?因为 AngularJS 试图避免像案例和未定义。查看值和模型值绑定和范围中定义。这就是$范围服务点 - 管理modelValue和viewValue

Why is this convienient? Because AngularJS tries to avoid having cases like null and undefined. View Values and Model Values are bound and defined by "scope". That's the point of the $scope service -- to manage the modelValue and viewValue.

直到一个 AngularJS 服务访问,它们将被默认为 number.NaN

这篇关于JavaScript数组是喃? AngularJS ngModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆