- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 183字
- 2021-07-15 17:05:28
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.
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Flutter跨平臺(tái)開(kāi)發(fā)入門(mén)與實(shí)戰(zhàn)
- PHP從入門(mén)到精通(第4版)(軟件開(kāi)發(fā)視頻大講堂)
- 速學(xué)Python:程序設(shè)計(jì)從入門(mén)到進(jìn)階
- Node.js開(kāi)發(fā)指南
- BeagleBone Robotic Projects(Second Edition)
- Kotlin極簡(jiǎn)教程
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程與水平考試指導(dǎo)
- Getting Started with Python
- Arduino Wearable Projects
- Docker:容器與容器云(第2版)
- C語(yǔ)言程序設(shè)計(jì)教程
- Java程序設(shè)計(jì)教程
- 你好!Java
- Python人工智能項(xiàng)目實(shí)戰(zhàn)