$viewValue and $模型值默认为Number.NaN
-- 非数字的 JavaScript 定义。
check Github https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1515你发现
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;
为什么这样方便呢?因为AngularJS尽量避免出现类似的情况null
and undefined
。视图值和模型值由“范围”绑定和定义。这就是 $scope 服务的重点——管理 modelValue 和 viewValue。
直到一个AngularJS服务访问它们,它们默认为number.NaN