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

If you want to improve youre preformence a little bit, you can use @Attribute decorator comes with Angular latest v6.

From code:

export type ButtonType = 'primary' | 'secondary';

@Component({
selector: 'app-button',
template: `
<button [ngClass]="type">
<ng-content></ng-content>
</button>
`
})
export class ButtonComponent {
@Input() type: ButtonType = 'primary';
} // use
<app-button type="secondary" (click)="click()">Click</app-button>

To code:

import { Component, Attribute } from '@angular/core';

export type ButtonType = 'primary' | 'secondary';

@Component({
selector: 'app-button',
template: `
<button [ngClass]="type">
<ng-content></ng-content>
</button>
`
})
export class ButtonComponent { constructor(@Attribute('type') public type: ButtonType = 'primary') { } }

With this change, Angular will evaluate it once and forget about it.

More information to follow:

Blog post

https://github.com/angular/angular.io/issues/1150

最新文章

  1. C#中的null与void
  2. 使用本地JConsole监控远程JVM(最权威的总结)
  3. Uvaoj 10048 - Audiophobia(Floyd算法变形)
  4. css-画三角箭头
  5. Markdown资源 markd
  6. 安装mmseg出错 config.status: error: cannot find input file: src/Makefile.in
  7. IOS开发-cell的动态高度
  8. netty常用代码
  9. Intellij IDEA13 创建多模块Maven项目
  10. spark 启动时候报 Unable to load native-hadoop library for your platform 警告
  11. [LeetCode] 148. Sort List 解题思路
  12. 在web应用程序中使用MemcachedClient
  13. 数学之路-python计算实战(13)-机器视觉-图像增强
  14. 转:LoadRunner获取毫秒及字符串替换实现
  15. unity下跨平台excel读写
  16. 简陋的斗地主,js实现
  17. shell参数传递
  18. Armstrong公理
  19. 简单Java动态代理实现
  20. echart 圆滑初始化化

热门文章

  1. POJ1179 Polygon 区间DP
  2. ajax跨域POST时执行OPTIONS请求服务端返回403forbidden的解决方法
  3. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交
  4. POJ3414 Pots
  5. BZOJ 1507 splay
  6. Web启动,停止Windows服务
  7. Openwrt PPTP Server笔记
  8. WP - 控件基础-按钮控件
  9. (转)Bootstrap3 概述
  10. 功分器 power divider