angular-docs-cn/public/docs/js/latest/api/annotations/Attribute-class.jade

73 lines
1.1 KiB
Plaintext

p.
<span class="location-badge">exported from <a href="/angular2/annotations">angular2/annotations</a></span>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/core/annotations/di.js#L53">angular2/src/core/annotations/di.js (line 53)</a>
:markdown
Specifies that a constant attribute value should be injected.
The directive can inject constant string literals of host element attributes.
## Example
Suppose we have an `<input>` element and want to know its `type`.
```html
<input type="text">
```
A decorator can inject string literal `text` like so:
```javascript
@Decorator({
selector: `input'
})
class InputDecorator {
constructor(@Attribute('type') type) {
// type would be `text` in this example
}
}
```
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
(attributeName)
:markdown
.l-sub-section
h3 attributeName
:markdown
.l-sub-section
h3 token
:markdown