官术网_书友最值得收藏!

Metadata

A class can be turned into a component by annotating it with @Component and passing the necessary metadata, such as selector, template, or templateUrl. Angular considers a class as a component only after attaching metadata to it:

Let's revisit the BookComponent class we defined earlier. Angular does not consider this class as a component unless we annotate it. TypeScript leverages the ES7 feature by providing a way to decorate a class with metadata as follows:

@Component({ 
  selector:    'book-detail', 
  templateUrl: 'app/book.component.html' 
}) 
export class BookComponent { ... } 

Here, we have decorated the BookComponent class with @Component and attached metadata selector and templateUrl. It means that, wherever Angular sees the special <book-detail/> tag in the view, it will create an instance of BookComponent and render the view assigned to templateUrl, which is book.component.html.

A decorator provided by TypeScript is a function that takes configuration parameters that are used by Angular to create an instance of the component and render the associated view. Configuration parameters may also have information about directives and providers, which will be made available by Angular when the component is created.

主站蜘蛛池模板: 南靖县| 安图县| 保德县| 宜丰县| 铜陵市| 广昌县| 花莲县| 荆州市| 武安市| 吴川市| 连城县| 特克斯县| 阳江市| 庆安县| 嘉禾县| 佛学| 井研县| 鄂尔多斯市| 葵青区| 兴国县| 恭城| 永修县| 宜春市| 汉川市| 安阳市| 图们市| 罗定市| 麻栗坡县| 司法| 同德县| 宣武区| 宁夏| 阿荣旗| 德化县| 通河县| 鹤岗市| 堆龙德庆县| 东丽区| 赫章县| 外汇| 凌云县|