zoukankan      html  css  js  c++  java
  • [Angular] Angular Attribute Decorator

    When we pass value to a component, normally we use @Input.

    <my-comp [courses]="(courses$ | async) as courses" ></my-comp>
    
    @Component({...})
    export class MyComp implements OnInit {
        @Input() courses;
        ...
    }

    Angular will check whether any update on @Input on each event fires in order to keep DOM update.  Which means if we have too many unncessary @Input, can cause profermance overhead. 

    By 'unncessary' I mean, the value won't change overtime.

    For example:

    <my-comp type="beginner" [courses]="(courses$ | async) as courses" ></my-comp>

    In this case, we can use @Attribute decorator:

    @Component({...})
    export class MyComp implements OnInit {
        @Input() courses;
        ...
         
        constructor (@Attribute('type') private type) {}
    }

    It is similar to AngularJS one time binding.

  • 相关阅读:
    hdu-2612-Find a way
    poj-1426-Find The Multiple
    POJ-2251-Dungeon Master
    树的遍历
    前序和中序+后序和中序
    哈夫曼树
    平衡二叉树
    队列和优先队列
    1213
    1163
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10320634.html
Copyright © 2011-2022 走看看