Attribute
decorator
Parameter decorator for a directive constructor that designates a host-element attribute whose value is injected as a constant string literal.
attributeName
string
The name of the attribute whose value can be injected.
Usage Notes
Suppose we have an <input>
element and want to know its type
.
<input type="text">
The following example uses the decorator to inject the string literal text
in a directive.
@Directive({ selector: 'input', standalone: false,})class InputAttrDirective { constructor(@Attribute('type') type: string) { // type would be 'text' in this example }}
The following example uses the decorator in a component constructor.
Jump to details