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

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.

主站蜘蛛池模板: 乐昌市| 曲水县| 正阳县| 宿州市| 辽阳市| 时尚| 台湾省| 嵩明县| 凤庆县| 益阳市| 新竹市| 宁化县| 皋兰县| 资阳市| 盖州市| 汝城县| 万州区| 周宁县| 新闻| 阆中市| 东港市| 保康县| 康乐县| 乾安县| 广丰县| 杭州市| 武平县| 汤阴县| 神木县| 额济纳旗| 邳州市| 崇州市| 澄城县| 桃园县| 承德县| 临安市| 四子王旗| 三门峡市| 新泰市| 沂南县| 井研县|