- 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.
- 少兒人工智能趣味入門:Scratch 3.0動畫與游戲編程
- C語言程序設計案例教程
- CMDB分步構建指南
- Android 9 Development Cookbook(Third Edition)
- PLC編程及應用實戰
- C語言實驗指導及習題解析
- Learning Data Mining with R
- Building Serverless Applications with Python
- SQL Server與JSP動態網站開發
- Unity 2017 Mobile Game Development
- CoffeeScript Application Development Cookbook
- 好好學Java:從零基礎到項目實戰
- JavaScript+jQuery網頁特效設計任務驅動教程
- Orchestrating Docker
- PostgreSQL Developer's Guide