Angular html property的值如何被更新的
2023-09-14 09:04:03 时间
html页面里有一个input element,通过语法[(ngModel)]双向绑定到model hero的name字段。
一旦往input field里输入新的值之后,触发core.js的refreshView方法,里面执行templateFn方法:
hero-detail.component.html对应一个方法:HeroDetailComponent_div_2_Template:
上图的方法负责更新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:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- Angular的依赖注入(依赖反转)原理说明
- [Angular HTML] Implementing The Input Mask Cursor Navigation Functionality -- setSelectionRange
- [Angular HTML] Overwrite input value, String.fromCharCode & input.selectionStart
- [Angular Form] ngModel and ngModelChange
- [Angular 2] @ngrx/devtools demo
- [Angular 2] *ngFor with index
- [AngularJS] Hijacking Existing HTML Attributes with Angular Directives
- [Angular] Angular Search filter, built-in filters, ng-repeat
- [Angular] Define a custom Material theme
- [Angular] Use Angular style sanitization to mark dynamic styles as trusted values
- [Angular Directive] Create a Template Storage Service in Angular 2
- Angular 应用要启用 Service Worker 所需满足的一些前提条件
- Angular 里的 Service Worker
- Angular 依赖注入里factory函数的调用时机
- Angular form控件原生HTML代码里ng-reflect-form属性和其值的生成时机
- 在Angular的index.html里插入script,拦截所有动态创建标签页的场景
- Angular单元测试ComponentFixture的实例化过程明细
- Angular应用双向绑定的语法糖