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

[Angular] Getting to Know the @Attribute Decorator in Angular的更多相关文章

  1. [Angular] Angular Attribute Decorator - When to use it?

    When we pass value to a component, normally we use @Input. <my-comp [courses]="(courses$ | a ...

  2. angular的跨域(angular百度下拉提示模拟)和angular选项卡

    1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...

  3. angular 2+ 变化检测系列三(Zone.js在Angular中的应用)

    在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...

  4. 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once

    自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...

  5. 【Angular专题】 (3)装饰器decorator,一块语法糖

    目录 一. Decorator装饰器 二. Typescript中的装饰器 2.1 类装饰器 2.2 方法装饰器 2.3 访问器装饰器 2.4 属性装饰器 2.5 参数装饰器 三. 用ES5代码模拟装 ...

  6. [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State

    ngrx/store is a library that simplifies common RxJS patterns for managing state and gives you an eas ...

  7. Angular开发实践(三):剖析Angular Component

    Web Component 在介绍Angular Component之前,我们先简单了解下W3C Web Components 定义 W3C为统一组件化标准方式,提出Web Component的标准. ...

  8. [转]使用 Angular CLI 和 ng-packagr 构建一个标准的 Angular 组件库

    使用 Angular CLI 构建 Angular 应用程序是最方便的方式之一. 项目目标 现在,我们一起创建一个简单的组件库. 首先,我们需要创建一个 header 组件.这没什么特别的,当然接下来 ...

  9. [Angular] Extract Implementation Details of ngrx from an Angular Application with the Facade Pattern

    Extracting away the implementation details of ngrx from your components using the facade pattern cre ...

随机推荐

  1. 【概率证明】—— sum and product rules of probability

    1. sum and product rules of probability ⎧⎩⎨p(x)=∫p(x,y)dyp(x,y)=p(x|y)p(y) sum rule of probability 的 ...

  2. 南海区行政审批管理系统接口规范v0.3(规划) 3.业务办理API 3.1.businessAuditById【业务办理】

    {"c_accept":"Q2015112400002","c_operators":"gz99","v_op ...

  3. Nginx实现负载均衡 + Keepalived实现Nginx的高可用

    前言 使用集群是大中型网站解决高并发.海量数据问题的常用手段.当一台服务器的处理能力.存储空间不足时,不要企图去换更强大的服务器,对大型网站而言,不管多么强大的服务器,都满足不了网站持续增长的业务需求 ...

  4. Docker 配置与实践清单

    https://mp.weixin.qq.com/s/yeEkF5DKa9IjmIvuzOTT3g

  5. href 与 src

    href:常用有两个标签<a>和<link> 1.<a href="http://www.w3school.com.cn">W3School&l ...

  6. 登录linux,输入ls显示anaconda-ks.cfg cobbler.ks ....., 原因在于root@ ~ / 区别

    今天登录linux测试机,想要创建目录,ls的时候,找不到之前的的目录,才发现是目录不对的问题. 首先,先要弄清楚 [root@330c353813ea ~] 和 [root@330c353813ea ...

  7. matplotlib学习笔记.CookBook

    matplotlib 是Python下的一个高质量的画图库,可以简单的类似于MATLAB方法构建高质量的图表. 原始文章地址:http://zanyongli.i.sohu.com/blog/view ...

  8. window窗口操作

    打开新窗口 window.open([url],[窗口名称],[参数字符串]) window.open("http://baidu.com","_balnk", ...

  9. 工欲善其事必先利其器之windows篇

    Windows是我们最常用的系统,下面就让我们重新认识一下Windows有哪些可以让我们提高工作效率的快捷键以及部分技巧,,以及在外行看来可以看起来逼格高的技巧! 1.Windows最实用,最常用的快 ...

  10. 版本控制之git学习

    最近学习了一下版本控制中比较符合开发者气质的Git,这里做一个总结.一来梳理所学的内容:二来也作为起点后续继续丰富.学习的方式主要为网络学习和个人实践.推荐两个学习网页,互相参考必有所成. 博客园:h ...