[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 ...
随机推荐
- 【反演复习计划】【COGS2431】爱蜜莉雅的求助
出题人怎么这么不认真啊==明明官方译名是爱蜜莉雅…… 而且我们爱蜜莉雅碳是有英文名哒!是Emilia.你那个aimiliya我实在是无力吐槽…… 不过抱图跑23333首先这很像约数个数和函数诶!但是唯 ...
- OleDbDataAdapter具体使用11
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- HDU-3374
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- AC日记——[NOIP2015]运输计划 cogs 2109
[NOIP2015] 运输计划 思路: 树剖+二分: 代码: #include <cstdio> #include <cstring> #include <iostrea ...
- codeforces Round 442 B Nikita and string【前缀和+暴力枚举分界点/线性DP】
B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- HDU 2521 反素数(数论,比较)
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...
- hdu6138(后缀数组)
hdu6138 题意 给出若干个字符串,每次查询两个字符串,求两个字符串的公共子串且在给出的某一个字符串中作为前缀的最大长度. 分析 求公共子串:后缀数组 判断前缀:字典树 求完后缀数组,遍历下 \( ...
- Linq 透明标识符 let
IEnumerable<Person> list = new List<Person> { , Id = }, , Id = }, , Id = }, , Id = }, , ...
- Combination Sum IV -- LeetCode
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- POJ 3168 Barn Expansion (几何基础)
[题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...