填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

AttributeDecorator

属性装饰器/构造函数的类型。

Type of the Attribute decorator / constructor function.

      
      interface AttributeDecorator {
  (name: string): any
  new (name: string): Attribute
}
    

方法

指令构造函数的参数修饰器,用于指定宿主元素属性,其值作为常量字符串文字注入。

Parameter decorator for a directive constructor that designates a host-element attribute whose value is injected as a constant string literal.

      
      (name: string): any
    
参数
name string
返回值

any

使用说明

假设我们有一个 <input> 元素,并且想知道它的 type

Suppose we have an <input> element and want to know its type.

      
      <input type="text">
    

以下示例使用装饰器将字符串文字 text 注入指令中。

The following example uses the decorator to inject the string literal text in a directive.

      
      @Directive({selector: 'input'})
class InputAttrDirective {
  constructor(@Attribute('type') type: string) {
    // type would be 'text' in this example
  }
}
    

The following example uses the decorator in a component constructor.

      
      @Component({selector: 'page', template: 'Title: {{title}}'})
class Page {
  title: string;
  constructor(@Attribute('title') title: string) {
    this.title = title;
  }
}
    
      
      new (name: string): Attribute
    
参数
name string
返回值

Attribute