Angular数据绑定的学习笔记
发布日期:2021-06-30 14:41:21 浏览次数:2 分类:技术文章

本文共 1816 字,大约阅读时间需要 6 分钟。

https://angular.io/guide/property-binding

Property binding in Angular helps you set values for properties of HTML elements or directives.

property binding用于给html元素或者Directive的属性设置值。

The metadata for a component tells Angular where to get the major building blocks that it needs to create and present the component and its view. In particular, it associates a template with the component, either directly with inline code, or by reference. Together, the component and its template describe a view.

Component同template一起,描述一个view.

directives: apply app logic to what gets displayed.

Without a framework, you would be responsible for pushing data values into the HTML controls and turning user responses into actions and value updates. Writing such push and pull logic by hand is tedious, error-prone, and a nightmare to read, as any experienced front-end JavaScript programmer can attest.

  • {
    {hero.name}}
    • 第一个用法,将Component hero.name属性的值显示到li元素中。
    • 第二个用法,将selectedHero,即hero-list Component的属性,传递到herodetail Component的hero属性中去。这是Component属性到Component属性间的值传递。

    第三个用法,当用户点击hero名称时,触发Component里的selectHero方法。

    Angular还有一种有用的双向绑定机制:

    In two-way binding, a data property value flows to the input box from the component as with property binding. The user’s changes also flow back to the component, resetting the property to the latest value, as with event binding.

    Angular模板是动态的,当模板被渲染时,根据template里的指令去转换DOM.

    Angular templates are dynamic. When Angular renders them, it transforms the DOM according to the instructions given by directives. A directive is a class with a @Directive() decorator.

    A component is technically a directive. Angular defines the @Component() decorator, which extends the @Directive() decorator with template-oriented features.

    Component技术上其实也是一种Directive,只不过在后者的基础上,扩展出了一整套面向模板的特性。

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

    转载地址:https://jerry.blog.csdn.net/article/details/112410669 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

    上一篇:SAP CRM系统UI checkbox的设计与实现
    下一篇:Angular应用页面里appId的生成逻辑和位置

    发表评论

    最新留言

    很好
    [***.229.124.182]2024年04月22日 22时41分49秒