[Angular] Angular Attribute Decorator - When to use it?
2023-09-14 08:59:15 时间
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.
相关文章
- Flutter get_it库,动态服务定位器
- 大数据给IT企业带来攫金市场新机遇
- [Angular] ngx-formly (AKA angular-formly for Angular latest version)
- [Angular 2] ROUTING IN ANGULAR 2 REVISITED
- Error:Cannot build Artifact ':war exploded' because it is included into a circul
- intellij idea you can copy and open it in browser
- [RxJS] Reactive pattern: Passing Observable and trigger side effect until it complete
- [Angular] USING ZONES IN ANGULAR FOR BETTER PERFORMANCE
- new sap.m.Select - how is it implemented
- atitit.《金刚经》与it软件项目管理的启发 读后感attilax
- 【Codeforces Round #185 (Div. 2) A】 Whose sentence is it?
- 在Angular单元测试代码的it方法里连续调用两次detectChange方法,会触发两次ngAfterViewInit吗
- Angular jasmine单元测试框架里使用it函数定义single spec
- Jasmine里的describe,it和expect函数
- vuex报错:‘xxx’was assigned to but it has no setter.
- 悟道—位IT高管20年的职场心经(读书笔记三)
- 002-读书笔记-企业IT架构转型之道-阿里巴巴中台战略思想与架构实战-第二章 构建业务中台的基础-共享服务体系简介
- hdu 1754 I Hate It(线段树之 单点更新+区间最值)
- 【云原生之Docker实战】使用Docker部署Snipe-It固定资产管理平台
- 程序员12星座性格分析,猜猜哪个星座最适合IT行业?