![](/img/trans.png)
[英]Angular @Attribute decorator and ComponentFactoryResolver
[英]How angular's @Attribute decorator works?
@Attribute
装饰器从主机返回指定属性的值。
例如:
@Directive({
selector: '[test]'
})
export class TestDirective {
constructor(@Attribute('type') type ) {
console.log(type); // text
}
}
@Component({
selector: 'my-app',
template: `
<input type="text" test>
`,
})
export class App {}
例如,当您不需要使用Inputs()
并且您不希望 Angular 在每个更改检测周期中重新检查值时,它很有用。 使用属性,您将获得一次价值,您就完成了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.