angular - 角度输入绑定性能
问题描述
对静态数据使用带括号和不带括号的输入绑定在性能上是否有任何差异?我是说
<my-component [customTitle]="'Hello World'"></my-component>
对比
<my-component customTitle="Hello World"></my-component>
如果有人分享一些与该主题相关的有用文章,我将不胜感激
解决方案
如果使用静态数据,请使用属性装饰器
在构造函数中
constructor(@Attribute('customTitle') private customTitle: string) {}
如果您想在 html 中使用,请使用public
而不是private
,如果您计划组件可以使用或不使用@Optional
constructor(@Optional() @Attribute('customTitle') public customTitle: string) {
//and you can use, e.g.
if (!this.customTitle)
this.title="a title by defect"
}
//or in your .html, e.g.
<div *ngIf="!customTitle">Title by defect</div>
{{customTitle}}
你可以检查一下Netanel Basal 的这个条目
推荐阅读
- php - 从 Laravel 资源集合中删除 null
- typescript - NestJS: Cannot find module in dev mode
- ios - In Debug Mode, API Request works. Release Mode, returns null
- vim - Leaving editor on number makes many duplicates across the screen
- typescript - TypeScript 泛型类型谓词
- api - How to get the total playtime for specific steam app?
- ios - Swift:如何在 tableView 中滚动时停止滚动,然后在最后一个 tableView 项目之后继续滚动?
- vb.net - Adding multiple textboxes real time
- python - If any of the lines in a list of lines contains a substring
- laravel - 在刀片文件中显示“laravel-love”喜欢计数