繁体   English   中英

angular 的 @Attribute 装饰器是如何工作的?

[英]How angular's @Attribute decorator works?

我是学习 Angular 的新手。 我正在angular.io上学习 angular 的装饰器。 关于@Attribute装饰器的信息不多 请任何人给我一些用例。

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM