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

  • Expert Angular
  • Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
  • 175字
  • 2021-07-15 17:05:28

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.

主站蜘蛛池模板: 乌拉特中旗| 西畴县| 山东省| 龙海市| 多伦县| 庆阳市| 竹溪县| 通化县| 阳春市| 阿拉尔市| 汨罗市| 油尖旺区| 原阳县| 合水县| 昌平区| 宁晋县| 上犹县| 清远市| 大荔县| 额尔古纳市| 吉首市| 教育| 大名县| 清徐县| 大兴区| 石家庄市| 深州市| 承德县| 罗城| 芒康县| 会昌县| 苍南县| 漾濞| 称多县| 泸西县| 剑阁县| 上饶市| 冀州市| 若尔盖县| 东山县| 于田县|