Câu hỏi phỏng vấn Angular
Câu hỏi

What's the difference between an Angular Component and Module ?

Câu trả lời

In Angular, a Component and a Module serve distinct but complementary roles in the structure and organization of applications.

Angular Component

An Angular Component is essentially a building block of an Angular application. It is defined using the @Component decorator, which allows you to mark a class as an Angular component and provide additional metadata that determines how the component should be processed, instantiated, and used at runtime. Components are responsible for rendering views, which are sets of screen elements that Angular can choose and modify according to your program logic and data. Each component defines its own view and data logic directly linked to the HTML template it controls, making it an integral part of the user interface.

Components consist of three primary parts:

  1. Template: HTML that declares what renders on the page.
  2. Class: It handles data and functionality. In the class, properties are defined for data binding and methods for logic.
  3. Metadata: Information that determines how the component should be processed.

Angular Module

An Angular Module, on the other hand, is a mechanism to group components, directives, pipes, and services that are related, in such a way that can be combined with other modules to create an application. An Angular Module is defined using the @NgModule decorator. This decorator provides metadata that describes the module, including declarations (the view classes that belong to this module), imports (other modules whose exported classes are needed by component templates declared in this module), exports (the subset of declarations that should be visible and usable in the component templates of other modules), and providers (creators of services that this module contributes to the global collection of services).

Modules serve several key roles:

  1. **Organize an application into cohesive blocks of func...
junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What is the difference between Structural and Attribute directives in Angular?

senior

Explain the purpose of Service Workers in Angular

entry

What is Routing Guard in Angular?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào