in Technology by
How does an Angular application work?

1 Answer

0 votes
by

Every Angular app consists of a file named angular.json. This file will contain all the configurations of the app. While building the app, the builder looks at this file to find the entry point of the application. Following is an image of the angular.json file:

    
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
          "outputPath": "dist/angular-starter",
          "index": "src/index.html",
          "main": "src/main.ts",
          "polyfills": "src/polyfills.ts",
          "tsConfig": "tsconfig.app.json",
          "aot": false,
          "assets": [
            "src/favicon.ico",
            "src/assets"
          ],
          "styles": [
            "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
            "src/style.css"
          ]
        }
      }
    
  

Inside the build section, the main property of the options object defines the entry point of the application which in this case is main.ts.
The main.ts file creates a browser environment for the application to run, and, along with this, it also calls a function called bootstrapModule, which bootstraps the application. These two steps are performed in the following order inside the main.ts file:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

platformBrowserDynamic().bootstrapModule(AppModule)

In the above line of code, AppModule is getting bootstrapped.
The AppModule is declared in the app.module.ts file. This module contains declarations of all the components.
Below is an example of app.module.ts file:

    
      import { BrowserModule } from '@angular/platform-browser';
      import { NgModule } from '@angular/core';
      import { AppComponent } from './app.component';

      @NgModule({
        declarations: [
          AppComponent
        ],
        imports: [
          BrowserModule
        ],
        providers: [],
        entryComponents: [],
        bootstrap: [AppComponent]
      })
      export class AppModule { }
    
  

As one can see in the above file, AppComponent is getting bootstrapped.
This component is defined in app.component.ts file. This file interacts with the webpage and serves data to it.
Below is an example of app.component.ts file:

    
      import { Component } from '@angular/core';

      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
      })
      export class AppComponent {
        title = 'angular';
      }
    
  

Each component is declared with three properties:
1. Selector - used for accessing the component
2. Template/TemplateURL - contains HTML of the component
3. StylesURL - contains component-specific stylesheets

After this, Angular calls the index.html file. This file consequently calls the root component that is app-root. The root component is defined in app.component.ts.
This is how the index.html file looks:

    
      <!doctype html>
      <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>Angular</title>
        <base href="/">
        <meta name="viewport" content="width=device-width, initial-scale=1">
      </head>
      <body>
        <app-root></app-root>
      </body>
      </html>
    
  

The HTML template of the root component is displayed inside the <app-root> tags.

Related questions

0 votes
    I have used angular-cli with systemJS and am now comfortable with its build process,test cases & component ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Trying to search trough extrnal api Weather servis. Api is tested and works fine. Problem: Enter value in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Trying to search trough extrnal api Weather servis. Api is tested and works fine. Problem: Enter value in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Can one make an angular application to render on the server-side?...
asked Jun 30, 2021 in Education by JackTerrance
0 votes
    What Is An Exciter And How Does It Work?...
asked Dec 12, 2020 in Technology by JackTerrance
0 votes
    How does one share data between components in Angular?...
asked Jun 30, 2021 in Technology by JackTerrance
0 votes
    ______ is the default view of the spreadsheet application. It’s a collection of cells arranged in the work area. Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    ______ is the default view of the spreadsheet application. It’s a collection of cells arranged in the work area. Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    I'm not sure why the change detection wouldn't work here. I've tried a few things, including a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I'm not sure why the change detection wouldn't work here. I've tried a few things, including a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    How does ChatGPT work?...
asked Jan 30, 2023 in Technology by JackTerrance
0 votes
    How does the Raspberry Pi work?...
asked Jan 20, 2023 in Technology by JackTerrance
0 votes
0 votes
    How does HTTP Basic Authentication work?...
asked Jun 23, 2021 in Technology by JackTerrance
0 votes
    How Does a Web Service Work?...
asked Mar 13, 2021 in Technology by JackTerrance
...