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

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.

主站蜘蛛池模板: 阳城县| 延津县| 长汀县| 玉溪市| 绍兴市| 南江县| 福建省| 乐清市| 陆良县| 平湖市| 盐亭县| 江阴市| 达孜县| 金坛市| 和平县| 图片| 万载县| 中江县| 景泰县| 龙门县| 天长市| 剑阁县| 达孜县| 彭水| 乌拉特中旗| 平利县| 苏尼特右旗| 信丰县| 盐亭县| 荣昌县| 乐昌市| 肃北| 宽城| 武功县| 翁源县| 论坛| 昌吉市| 夏河县| 乐至县| 许昌市| 高邮市|