Bootstrapping of the Angular Application
ANGULAR BOOTSTRAPPING

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 works?

Bootstrapping is the process of loading the whole Angular Application.

Understanding the bootstrapping process gives you a great insight of the Angular architectural design as well as the connection of various parts of angular like modules, components, directives, services, dependency injection, pipes with each other.

It also gives you an understanding of how Angular segregate their functionalities, still make them work together as a whole application.

If you are the one who get's scared of the long file structure; believe me it's a very straightforward procedure, so let's get started:

  • The file structure of the Angular application is as follows:
  • The bootstrap process loads main.ts which is the main entry point of the application.
  • Keeping the main.ts file separate only for the bootstrapping process is a good way to isolate components from the bootstrap call. It gives a better organisation structure to the application with an easier test and reuse.
  • Let’s look what’s there in main.ts file:
  • Angular application can run in NativeScript, or Cordova, or any other environment that can host Angular applications. The environment of the application determines the platform to be imported for the bootstrapping process. For example, for browser specific application @angular/platform-browser-dynamic is used.
  • The platformBrowserDynamic().bootstrapModule function calls the AppModule and kick-starts the process. This is how the AppModule acts as the root module and loads at the start of the application.
  • Every application has at least one Angular module, the root module that you bootstrap to launch the application. By convention, it is usually called AppModule.
  • This is how an AppModule looks like:
  • AppModule is a class with @NgModule decorator. An NgModule decorator describes how the application parts fit together. It takes a metadata object with the properties: declarations, imports, providers, bootstrap and tells Angular how to compile and launch the application.
  • Just like AppModule is the root module, AppComponent is the root component that loads on the bootstrap. The bootstrap property in the @NgModule decorator register’s AppComponent as the root component.
  • Now if we have a look of AppComponent we will see the selector name in @component decorator as ‘app-root’.
  • The index.html file has HTML tag <app-root> with the same name as the selector name of the AppComponent.
  • This is how AppComponent is the first component that gets rendered on bootstrap into the view. As Angular has hierarchical component structure you can embed other components into the template of the AppComponent.
  • This helps in keeping the index.html file clean.


Hence, The bootstrap process loads main.ts which is the main entry point of the application. The AppModule operates as the root module of our application. The module is configured to use AppComponent as the component to bootstrap, and will be rendered on any app-root HTML element encountered.

Hope you can now make out how the whole application connects and works altogether.Feel free to share your experiences in the comments section.

Ajinkya Rananavare

Actively looking for job change Sr. Software Engineer

6 年

????

回复

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

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 条评论
  • Angular Architecture

    Angular Architecture

    The main building blocks of Angular are: Modules Components Templates, Directives, and Data Binding Services and…

    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…

社区洞察

其他会员也浏览了