Angular Architecture
ANGULAR ARCHITECTURE

Angular Architecture

The main building blocks of Angular are:

  • Modules
  • Components
  • Templates, Directives, and Data Binding
  • Services and Dependency Injection

Modules

Angular apps are modular and Angular has its own modularity system called Angular Modules or NgModules.

Every Angular app has a root module, conventionally named AppModule, which provides the bootstrap mechanism that launches the application. An app typically contains many functional modules.

NgModules can import functionality from other NgModules, and allow their own functionality to be exported and used by other NgModules.

NgModule is a decorator function that takes a single metadata object whose properties describe the module. The most important properties are:

  • declarations - declares the components, directives and pipes used in the application.
  • exports - the declarations that could be used in the component templates of other modules.
  • imports - the declarations of other modules that could be used in this module.
  • providers - the declarations of the singleton services that could be used throughout the application.
  • bootstrap - the root module sets the root component that hosts all other app view at the start of the application.

Components

Every Angular application has at least one component, the root component that connects a component hierarchy with the page document object model (DOM).

Each component defines a class that contains application data and logic, and is associated with an HTML template that defines a view to be displayed in a target environment.

The @Component() decorator identifies the class immediately below it as a component, and provides the template and related component-specific metadata.

Decorators are functions that modify JavaScript classes. Angular defines a number of decorators that attach specific kinds of metadata to classes, so that the system knows what those classes mean and how they should work.

Templates, directives and data binding

A template is a form of HTML that tells Angular how to render the component. A template combines HTML with Angular markup that can modify HTML elements before they are displayed. 

Template directives provide program logic, and binding markup connects your application data and the DOM. There are two types of data binding:

  • Event binding lets your app respond to user input in the target environment by updating your application data.
  • Property binding lets you interpolate values that are computed from your application data into the HTML.

Before a view is displayed, Angular evaluates the directives and resolves the binding syntax in the template to modify the HTML elements and the DOM, according to your program data and logic. Angular supports two-way data binding, meaning that changes in the DOM, such as user choices, are also reflected in your program data.

  • The {{product.name}} interpolation displays the component’s name property value within the <li> element.
  • The [product] property binding passes the value of selectedProduct from the parent ProductListComponent to the product property of the child ProductDetailComponent.
  • The(click) event binding calls the component’s selectProduct method when the user clicks a movies’s name.

Services and dependency injection

For data or logic that is not associated with a specific view, and that you want to share across components, you create a service class. A service class definition is immediately preceded by the @Injectable() decorator. The decorator provides the metadata that allows your service to be injected into client components as a dependency.

Dependency injection (DI) lets you keep your component classes lean and efficient. They don't fetch data from the server, validate user input, or log directly to the console; they delegate such tasks to services.

(Note: *** Here I am just mentioning the brief details of the topics as I will be covering these topics in detail in the coming articles. This is just to make you familiar with the Architecture.)

Resource: https://angular.io

When you're familiar with these fundamental building blocks, you can explore them in more detail.

Himanshi K.

Software Engineer at Ancestry

6 年

Priya Jolly?Check this out

要查看或添加评论,请登录

Nagma Bano的更多文章

  • Angular Lifecycle Hooks

    Angular Lifecycle Hooks

    Angular Lifecycle Hooks are the different phases of the component from its creation to its destruction where we can…

  • Data Communication In Angular

    Data Communication In Angular

    Data sharing is one of the important concept to understand in Angular. How Angular communicates data from and to…

    4 条评论
  • Introduction to Data binding

    Introduction to Data binding

    Data-binding is the mechanism for coordinating the parts of a template with the parts of the component. You can achieve…

  • Modules in Angular

    Modules in Angular

    Modules are a great way to organize an application and extend it with capabilities from external libraries. NgModules…

  • Templating, Styling and Component Hierarchy in Angular

    Templating, Styling and Component Hierarchy in Angular

    In Angular, your views are defined within HTML templates. A template is a form of HTML that tells Angular how to render…

    1 条评论
  • Introduction to Components

    Introduction to Components

    The core concept of any Angular application is the component. In effect, the whole application can be modeled as a tree…

    1 条评论
  • Bootstrapping of the Angular Application

    Bootstrapping of the Angular Application

    Seeing the complexity of the Angular file structure, the first question that comes to the mind is how does it actually…

    1 条评论
  • Getting Started With Angular

    Getting Started With Angular

    To start working with Angular we need to first set up the development environment. A development environment is one…

    1 条评论
  • Angular Features and Benefits

    Angular Features and Benefits

    Angular is one of the most popular modern day web frameworks available today. Because of the sheer support of Google…

  • Angular6 Vs Angular5

    Angular6 Vs Angular5

    Angular 5 Angular 5 showed up on November 1, 2017 with the promise of speed and a smaller size. The key features of…

社区洞察

其他会员也浏览了