mia*_*mia 5 angular2-decorators angular
我是新来学习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 {}
Run Code Online (Sandbox Code Playgroud)
例如,当您不需要使用Inputs()并且您不想Angular在每个变更检测周期中重新检查该值时,它很有用。有了Attribute,您就可以一次获得值,然后就完成了。