[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 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:
https://github.com/angular/angular.io/issues/1150
[Angular] Getting to Know the @Attribute Decorator in Angular的更多相关文章
- [Angular] Angular Attribute Decorator - When to use it?
		When we pass value to a component, normally we use @Input. <my-comp [courses]="(courses$ | a ... 
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
		1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ... 
- angular 2+ 变化检测系列三(Zone.js在Angular中的应用)
		在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ... 
- 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once
		自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ... 
- 【Angular专题】 (3)装饰器decorator,一块语法糖
		目录 一. Decorator装饰器 二. Typescript中的装饰器 2.1 类装饰器 2.2 方法装饰器 2.3 访问器装饰器 2.4 属性装饰器 2.5 参数装饰器 三. 用ES5代码模拟装 ... 
- [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 ... 
- Angular开发实践(三):剖析Angular Component
		Web Component 在介绍Angular Component之前,我们先简单了解下W3C Web Components 定义 W3C为统一组件化标准方式,提出Web Component的标准. ... 
- [转]使用 Angular CLI 和 ng-packagr 构建一个标准的 Angular 组件库
		使用 Angular CLI 构建 Angular 应用程序是最方便的方式之一. 项目目标 现在,我们一起创建一个简单的组件库. 首先,我们需要创建一个 header 组件.这没什么特别的,当然接下来 ... 
- [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 ... 
随机推荐
- mybits 操作指南
			第一.一对一: <resultMap type="com.zktx.platform.entity.tb.Module" id="BaseResultMap&quo ... 
- HIT Software Construction Lab6引发出来对锁的问题的探究
			前言 做完lab5开始做lab6了鸭,哈工大计算机学院的学生永不停歇.在做lab6的时候,我在想移动猴子是锁一整个ladder(ADT)还是只锁一个ladder的一个域Monkey数组呢?这两个好像差 ... 
- 一个域名如何解析到多个ip地址
			一.域名解析多ip实例 简单一句话: dns 解析时多添加几个不同IP的A记录 例如: 上图中我给域名解析到两个不同的ip,大概等十分钟后我们ping 一下的结果如下 可以看到已经实现了一个域名解析到 ... 
- WinForm中DataReader绑定到DataGridView的两种方法
			在WinForm中,DataReader是不能直接绑定到DataGridView的,我想到了用两种方法来实现将DataReader绑定到DataGridView. SqlCommand command ... 
- 第7章 性能和可靠性模式 Server Clustering(服务器群集)
			上下文 您正在设计要部署应用程序的基础结构层.运行要求包括无法满足的可用性或性能能力,因为基础结构中存在性能瓶颈或故障单点. 影响因素 设计基础结构时,请考虑下列影响因素: 用户希望在使用应用程序时这 ... 
- Three学习之曲线
			曲线 属性 1. .arcLengthDivisions 当通过.getLengths计算曲线的累积段长度时,此值决定了分割的数量.为了确保在使用.getSpacedPoint等方法时的精度,如果曲线 ... 
- express  jade  ejs  为什么要用这些?
			express是快速构建web应用的一个框架 线上文档 http://www.expressjs.com.cn/ 不用express行不行呢? 看了网上的回答:不用express直接搭,等你 ... 
- hdu2883  最大流,判断满流  优化的SAP算法
			这是09年的多校联赛题目,比10年的难度要大.如果没做过hdu3572,建议先去做.有了解题思维再来做这题. 这题与hdu3572类似.但是1 <= si < ei <= 1,000 ... 
- C#自定义控件实现控件随窗口大小改变
			1.新建用户控件,取名MyForm. 2.将默认的UserControl改成Form 3.在类中添加以下代码 private float X, Y; //获得控件的长度.宽度.位置.字体大小的数据 p ... 
- H5动效的常见制作手法
			众所周知,一个元素,动往往比静更吸引眼球: 一套操作界面,合适的动态交互反馈能给用户带来更好的操作体验: 一个H5运营宣传页,炫酷的动画特效定能助力传播和品牌打造. 近两年,小到loading动画,表 ... 
