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. [ACM] HDU 5086 Revenge of Segment Tree(全部连续区间的和)

    Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...

  2. 智能识别收货地址 javascript

    欢迎加入前端交流群交流知识&&获取视频资料:749539640 地址: https://github.com/wzc570738205/smart_parse

  3. Solr.NET快速入门(五)【聚合统计,分组查询】

    聚合统计 属性 说明 Min 最小值 Max 最大值 Sum 总和 Count 记录数,也就是多少行记录 Missing 结果集中,有多少条记录是空值 SumOfSquares 平方和(x1^2 + ...

  4. merge into语句的使用

    merge语法是根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入. 其基本语法规则是 merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a ...

  5. damn selenium

    Selenium+Python [ˈpaɪθən] 0.Selenium安装 pip install selenium 1.打开了浏览器,后边什么都不干了 需要将浏览器驱动放置在环境变量的目录下. 2 ...

  6. layoutInflater的用途以及获取VIEW方法

    如果需要用到自定义多个布局,就需要用到layoutInflater,获取layoutInflater一般有几种方式,但我在实际使用中,感觉如下的getLayoutInflater()是最为方便的,不用 ...

  7. iOS11关于隐藏导航栏后带有tableView界面出现,下移问题

    //解决iOS11关于隐藏导航栏后带有scrollView界面出现,下移问题 if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdj ...

  8. 【Oracle】创建角色

    任务:创建角色 1)创建角色sse_role,授予create session 权限 2)创建角色tblo_role,授予CREATE PROCEDURE, CREATE SEQUENCE, CREA ...

  9. vue-cli 安装

    1    node 下载      http://nodejs.cn/download/ 安装 2  npm install vue-cli -g 3  vue init <template-n ...

  10. RAP开发入门-主题更换

    通过配置扩展点修改应用主题    ps:需要提前准备好主题(theme.css)文件   <!-- 注册主题扩展点 -->    <extension          point= ...