Angular html property的值如何被更新的

html页面里有一个input element,通过语法[(ngModel)]双向绑定到model hero的name字段。

Angular html property的值如何被更新的_第1张图片

一旦往input field里输入新的值之后,触发core.js的refreshView方法,里面执行templateFn方法:

Angular html property的值如何被更新的_第2张图片

hero-detail.component.html对应一个方法:HeroDetailComponent_div_2_Template:

Angular html property的值如何被更新的_第3张图片
Angular html property的值如何被更新的_第4张图片

上图的方法负责更新element的property:

/**
 * @license
 * Copyright Google LLC All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */
/**
 * Update a property on a selected element.
 *
 * Operates on the element selected by index via the {@link select} instruction.
 *
 * If the property name also exists as an input property on one of the element's directives,
 * the component property will be set instead of the element property. This check must
 * be conducted at runtime so child components that add new `@Inputs` don't have to be re-compiled
 *
 * @param propName Name of property. Because it is going to DOM, this is not subject to
 *        renaming as part of minification.
 * @param value New value to write.
 * @param sanitizer An optional function used to sanitize the value.
 * @returns This function returns itself so that it may be chained
 * (e.g. `property('name', ctx.name)('title', ctx.title)`)
 *
 * @codeGenApi
 */

el是html的原生element,即input field:

Angular html property的值如何被更新的_第5张图片
Angular html property的值如何被更新的_第6张图片
Angular html property的值如何被更新的_第7张图片
Angular html property的值如何被更新的_第8张图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

你可能感兴趣的:(TypeScript,Angular)