angular : ngModel 内部流程

时间:2023-12-29 17:07:32

angular 1.5 beta link

NgModelController provides API for the ngModel directive. The controller contains services for data-binding, validation, CSS updates, and value formatting and parsing. It purposefully does not contain any logic which deals with DOM rendering or listening to DOM events. Such DOM related logic should be provided by other directives which make use of NgModelController for data-binding to control elements. Angular provides this DOM logic for most input elements. At the end of this page you can find a custom control example that uses ngModelController to bind to contenteditable elements.

NgModelController 为NgModel指令提供了API。控制器服务有data-binding,验证,css更新和value 格式化和解析。主要目的是不涉及Dom 渲染和监听Dom事件。Dom的关联逻辑应该由指令提供,内部由NgModelController负责data-binding。Angular 提供了Dom的逻辑大部分是为了Input element。剩下没必要翻译

$render();

渲染Dom!

视图需要更新时调用。$rollbackViewValue()被调用。

NgModel不做了深监听,只有$modelValue和$viewValue的值不一样时才会执行当之前的value有变化。如果$modelValue和$viewValue是对象将不会调用

$isEmpty(value);

这被调用当我们需要确定是否输入的值是空的。

required 指令将调用这功能,过滤undefined''null or NaN.