Angular2 - Class - AttributeMetadata

Specifies that a constant attribute value should be injected.
The directive can inject constant string literals of host element attributes.

注入此指令获取当前元素的属性用

@Directive({ selector: 'input' })
class InputAttrDirective {
constructor( @Attribute('id') id) {
console.log(id);
}
}

...
<input type="text"
id="skuInput"
placeholder="SKU"
ngControl="sku">

可以得到结果

id
>"skuInput"