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.

[Angular] Angular Attribute Decorator - When to use it?的更多相关文章

  1. [Angular] Getting to Know the @Attribute Decorator in Angular

    So when you using input binding in Angular, it will always check for update. If you want to improve ...

  2. Angular - - angular.Module

    angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...

  3. Angular - - angular.injector、angular.module

    angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...

  4. Angular - - Angular数据类型判断

    angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...

  5. Angular - - angular.uppercase、angular.lowercase、angular.fromJson、angular.toJson

    angular.uppercase 将指定的字符串转换成大写 格式:angular.uppercase(string); string:被转换成大写的字符串. 使用代码: var str = &quo ...

  6. Angular - - angular.bind、angular.bootstrap、angular.copy

    angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...

  7. Angular - - angular.element

    angular.element 将DOM元素或者HTML字符串一包装成一个jQuery元素. 格式:angular.element(element); element:包装成jquery对象的html ...

  8. Angular - - angular.equals

    angular.equals 对比两个对象/值是否相等.支持值类型.正则表达式.数组和对象. 如果下列至少有一个是正确的,则将两个对象/值视为相等. 两个对象/值能通过===比较. 两个对象/值是同一 ...

  9. Angular - - angular.identity和angular.noop

    angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. 格式:angular.identity() 使用代码: (function () { angular.modul ...

随机推荐

  1. LINUX环境下的GUN MAKE学习笔记(二)

    第三章:makefile总述 3.1makefile的内容 在一个完整的makefile中,包含显示规则.隐含规则.变量定义.指示符和注释.下面讨论一些基本概念: 显示规则:它描述了在何种情况下如何更 ...

  2. HTML5-坦克大战一画出敌人坦克并让自己的坦克可以发子弹的功能(二)

    上一篇博客只画出了,一个坦克,并让其可以上下左右移动,这篇博客将画出敌人的坦克,并让自己的坦克可以发子弹,但是还不是尽善尽美,还有一些问题,将会在下篇博客说明: html代码: <!DOCTYP ...

  3. [译]lambda表达式对 SAM (单个抽象方法类)type的处理方式

    在阅读Venkat Subramaniam的著作<Functional Programming in Java> 之后,方法模式和lambda完美结合让我印象深刻. 这种模式经常用作数据源 ...

  4. python-函数(命名空间、作用域、闭包)

    一.命名空间 全局命名空间 局部命名空间 内置命名空间 *内置命名空间中存放了python解释器为我们提供的名字:input,print,str,list,tuple...它们都是我们熟悉的,拿过来就 ...

  5. Java多态机制和继承中重写重载

    关于Java中多态机制 http://www.cnblogs.com/chenssy/p/3372798.html 这篇博文讲的很透彻 大体意思是 多态定义: 多态就是指程序中定义的引用变量所指向的具 ...

  6. Remove @Override annotation错误提示

    因为对于JDK5.0/1.5版本来说,@Override annotation只能用与对超类的方法重写上, 而不能用在对接口方法的实现方法上. 解决的方法是把JDK改为1.6的或动手把注释@Overr ...

  7. 将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table

    将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table xxx 新年新气象,果然在新年的第一天就遇到了一个大坑,项目在win上跑的没 ...

  8. POJ 2367 Genealogical tree【拓扑排序/记录路径】

    Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7101 Accepted: 4585 Spe ...

  9. golang笔记:net/smtp

    跟go语言的net/smtp斗争了一天,记录下历程.   先用最标准的例子 host := net.JoinHostPort(hostname, port) auth := smtp.PlainAut ...

  10. 线段树【p4879】ycz的妹子

    Description 机房神犇yczycz有n个青梅竹马,她们分别住在1~n号城市中.小时候的她们美丽可爱,但是由于女大十八变,有些妹子的颜值发生了变化,但是十分重感情的\(ycz\)神犇不忍心抛弃 ...