Angular开发模式下的setNgReflectProperties函数

60 阅读1分钟

执行上下文:detectChange触发的refreshView里:

LView:

待测试的视图:


datavalue:

value:

type:3 - element
type:0 - container

function setNgReflectProperties(lView, element, type, dataValue, value) {
    if (type === 3 /* Element */ || type === 0 /* Container */) {
        /**
         * dataValue is an array containing runtime input or output names for the directives:
         * i+0: directive instance index
         * i+1: privateName
         *
         * e.g. [0, 'change', 'change-minified']
         * we want to set the reflected property with the privateName: dataValue[i+1]
         */
        for (let i = 0; i < dataValue.length; i += 2) {
            setNgReflectProperty(lView, element, type, dataValue[i + 1], value);
        }
    }
}

index为11,RENDER,代表renderer对应的entry:

Directive的值:

设置调试信息:

normalizeDebugBindingValue函数的输入:autofocus: “:host”
输出:"[object Object]"

最后,DOM Renderer调用HTML element原生的setAttribute设置出于调试目的的属性:

更多Jerry的原创文章,尽在:“汪子熙”: