JavaScript数组是喃? AngularJS ngModel [英] JavaScript array is NaN? 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屋!