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

Components

A component is a class that has properties and methods to be used in the view. These properties and methods exposed to view enable the view to interact with components. We code logic that supports the view in the component class:

For example, next is a component class book that has a properties title and author and a getPubName method that returns the name of the book:

export class BookComponent { 
  title: string; 
  author: string; 
  constructor() { 
      this.title = 'Learning Angular for .Net Developers'; 
      this.author = 'Rajesh Gunasundaram'; 
  } 
  getPubName() : string { 
    return 'Packt Publishing'; 
  } 
} 
Note: We will be using TypeScript in all our examples in this book.

The life cycle of a component is managed by Angular according to user interactions with the application. We can also add an event method that will be fired according to the state changes of the component. These event methods are known as life cycle hooks and are optional.

We will learn in detail about components in Chapter 5, Implementing Angular Routing and Navigation.

主站蜘蛛池模板: 新邵县| 彰化市| 涿鹿县| 菏泽市| 宜丰县| 朝阳市| 长白| 津市市| 潞城市| 固原市| 滨州市| 类乌齐县| 江城| 墨脱县| 仙桃市| 饶阳县| 咸丰县| 民丰县| 南召县| 佳木斯市| 盐津县| 泗阳县| 衡南县| 阿克| 万全县| 西乌珠穆沁旗| 定安县| 吐鲁番市| 肇源县| 翁源县| 昔阳县| 滁州市| 莱西市| 阳信县| 光泽县| 崇阳县| 辽源市| 澜沧| 略阳县| 丹巴县| 武陟县|