[Angular] Angular Attribute Decorator - When to use it?
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?的更多相关文章
- [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 ...
- Angular - - angular.Module
angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...
- Angular - - angular.injector、angular.module
angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...
- Angular - - Angular数据类型判断
angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...
- Angular - - angular.uppercase、angular.lowercase、angular.fromJson、angular.toJson
angular.uppercase 将指定的字符串转换成大写 格式:angular.uppercase(string); string:被转换成大写的字符串. 使用代码: var str = &quo ...
- Angular - - angular.bind、angular.bootstrap、angular.copy
angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...
- Angular - - angular.element
angular.element 将DOM元素或者HTML字符串一包装成一个jQuery元素. 格式:angular.element(element); element:包装成jquery对象的html ...
- Angular - - angular.equals
angular.equals 对比两个对象/值是否相等.支持值类型.正则表达式.数组和对象. 如果下列至少有一个是正确的,则将两个对象/值视为相等. 两个对象/值能通过===比较. 两个对象/值是同一 ...
- Angular - - angular.identity和angular.noop
angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. 格式:angular.identity() 使用代码: (function () { angular.modul ...
随机推荐
- win32 读取文本文件,并进行字符串分割和存储
//分割字符 char *p;//p存放临时行指针 q存放临时每一行的列指针 char *hang[100]={0};//存储第一行 char *lie[300]={0} ...
- php必备树状数组处理方法
thinkphp必备公共方法 /** * 子元素计数器 * @param array $array * @param int $pid * @return array */ function arra ...
- ubuntu 启动 重启 停止 apache
一.Start Apache 2 Server /启动apache服务 # /etc/init.d/apache2 start or $ sudo /etc/init.d/apache2 start ...
- HDU 2102 A计划【三维BFS】
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...
- 2018 ACM-ICPC 沈阳网络赛
Problem A Problem B Problem C Problem D Problem E Problem F Problem G Problem H Problem I Problem J ...
- Manacher【p1210】回文检测
题目描述--->P1210 回文检测 分析: 看到回文显然想到了manacher算法(线性求解回文串问题 如果不了解还是去敲一下板子,学习一下比较好.-->manacher 题目要求我们求 ...
- ( 转 ) mysql复合索引、普通索引总结
对于复合索引:Mysql从左到右的使用索引中的字段,一个查询可以只使用索引中的一部份,但只能是最左侧部分.例如索引是key index (a,b,c). 可以支持a | a,b| a,b,c 3种组合 ...
- [BZOJ 1833] 数字计数
Link: BZOJ 1833 传送门 Solution: 比较明显的数位DP 先预处理出1~9和包括前导0的0的个数:$pre[i]=pre[i-1]*10+10^{digit-1}$ (可以分为首 ...
- 【斜率优化】BZOJ1010 [HNOI2008]玩具装箱toy
[题目大意] P教授有编号为1...N的N件玩具,第i件玩具长度为Ci.为了方便整理,P教授要求在一个一维容器中的玩具编号是连续的.如果将第i件玩具到第j个玩具放到一 个容器中,那么容器的长度将为 x ...
- 【Treap模板详细注释】BZOJ3224-普通平衡树
模板题:D错因见注释 #include<iostream> #include<cstdio> #include<cstring> #include<algor ...