Return to site

ANGULAR: How does an Angular application get started? ๐Ÿš€

ยท ngInterview,fullstack

An Angular application gets loaded or started by the following way:

1๏ธโƒฃ ๐‹๐จ๐š๐ ๐ข๐ง๐๐ž๐ฑ.๐ก๐ญ๐ฆ๐ฅ ๐Ÿš€

The starting point of any Angular web application is the index.html page.

Code ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

<โ„Ž๐‘ก๐‘š๐‘™ ๐‘™๐‘Ž๐‘›๐‘”="๐‘’๐‘›">

<โ„Ž๐‘’๐‘Ž๐‘‘>

...

<๐‘ก๐‘–๐‘ก๐‘™๐‘’>๐บ๐‘’๐‘ก๐‘ก๐‘–๐‘›๐‘”๐‘†๐‘ก๐‘Ž๐‘Ÿ๐‘ก๐‘’๐‘‘

...

<๐‘๐‘œ๐‘‘๐‘ฆ>

<๐‘Ž๐‘๐‘-๐‘Ÿ๐‘œ๐‘œ๐‘ก>

...

<๐’”๐’„๐’“๐’Š๐’‘๐’• ๐’”๐’“๐’„="๐’Ž๐’‚๐’Š๐’-๐’†๐’”2015.๐’‹๐’”" ๐’•๐’š๐’‘๐’†="๐’Ž๐’๐’…๐’–๐’๐’†">

<๐’”๐’„๐’“๐’Š๐’‘๐’• ๐’”๐’“๐’„="๐’Ž๐’‚๐’Š๐’-๐’†๐’”5.๐’‹๐’”" ๐’๐’๐’Ž๐’๐’…๐’–๐’๐’† ๐’…๐’†๐’‡๐’†๐’“>

๐Ÿ’ก Notice the main.js which has the application code in it.

2๏ธโƒฃ ๐„๐ฑ๐ž๐œ๐ฎ๐ญ๐ž ๐ฆ๐š๐ข๐ง.๐ญ๐ฌ ๐…๐ข๐ฅ๐ž โšก

The code inside the main.js file is the entry point for the application.

It does this thanks to the module platformBrowserDynamic.

Code ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

๐‘๐‘™๐‘Ž๐‘ก๐‘“๐‘œ๐‘Ÿ๐‘š๐ต๐‘Ÿ๐‘œ๐‘ค๐‘ ๐‘’๐‘Ÿ๐ท๐‘ฆ๐‘›๐‘Ž๐‘š๐‘–๐‘().๐‘๐‘œ๐‘œ๐‘ก๐‘ ๐‘ก๐‘Ÿ๐‘Ž๐‘๐‘€๐‘œ๐‘‘๐‘ข๐‘™๐‘’(๐ด๐‘๐‘๐‘€๐‘œ๐‘‘๐‘ข๐‘™๐‘’);

๐Ÿ’ก This loads the AppModule.

3๏ธโƒฃ ๐‹๐จ๐š๐ ๐€๐ฉ๐ฉ-๐‹๐ž๐ฏ๐ž๐ฅ ๐Œ๐จ๐๐ฎ๐ฅ๐ž ๐Ÿ“ฆ

The app-level module or root module has one app-level component or root component.

The bootstrap property or key of the NgModule decorator specifies which component should be loaded by Angular when the app-level module loads.

Code ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

๐‘๐‘œ๐‘œ๐‘ก๐‘ ๐‘ก๐‘Ÿ๐‘Ž๐‘: [๐ด๐‘๐‘๐ถ๐‘œ๐‘š๐‘๐‘œ๐‘›๐‘’๐‘›๐‘ก]

๐Ÿ’ก Thus the AppComponent is loaded.

4๏ธโƒฃ ๐‹๐จ๐š๐ ๐€๐ฉ๐ฉ-๐‹๐ž๐ฏ๐ž๐ฅ ๐‚๐จ๐ฆ๐ฉ๐จ๐ง๐ž๐ง๐ญ โš™๏ธ

The App component controller contains:

Code ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

@๐ถ๐‘œ๐‘š๐‘๐‘œ๐‘›๐‘’๐‘›๐‘ก({

๐‘ ๐‘’๐‘™๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ: '๐‘Ž๐‘๐‘-๐‘Ÿ๐‘œ๐‘œ๐‘ก',

๐‘ก๐‘’๐‘š๐‘๐‘™๐‘Ž๐‘ก๐‘’๐‘ˆ๐‘Ÿ๐‘™: './๐‘Ž๐‘๐‘.๐‘๐‘œ๐‘š๐‘๐‘œ๐‘›๐‘’๐‘›๐‘ก.โ„Ž๐‘ก๐‘š๐‘™',

๐‘ ๐‘ก๐‘ฆ๐‘™๐‘’๐‘ˆ๐‘Ÿ๐‘™๐‘ : ['./๐‘Ž๐‘๐‘.๐‘๐‘œ๐‘š๐‘๐‘œ๐‘›๐‘’๐‘›๐‘ก.๐‘ ๐‘๐‘ ๐‘ ']

})

๐‘’๐‘ฅ๐‘๐‘œ๐‘Ÿ๐‘ก ๐‘๐‘™๐‘Ž๐‘ ๐‘  ๐ด๐‘๐‘๐ถ๐‘œ๐‘š๐‘๐‘œ๐‘›๐‘’๐‘›๐‘ก {...

๐Ÿ’ก Thus, the next step is the proceeding of the template app.component.html.

5๏ธโƒฃ ๐๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐“๐ž๐ฆ๐ฉ๐ฅ๐š๐ญ๐ž ๐Ÿ–ผ๏ธ

The templateURL property points to the HTML template file, which will be rendered to the browser when this component is processed.

And this template in html will call the components whcih will call other components till you get all you require according to your app design.

Code ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

<โ„Ž๐‘’๐‘Ž๐‘‘๐‘’๐‘Ÿ>

<๐‘‘๐‘–๐‘ฃ ๐‘๐‘™๐‘Ž๐‘ ๐‘ ="๐‘™๐‘Ž๐‘ฆ๐‘œ๐‘ข๐‘ก-๐‘๐‘œ๐‘™๐‘ข๐‘š๐‘› ๐‘–๐‘ก๐‘’๐‘š-๐‘™๐‘–๐‘ ๐‘ก ๐‘—๐‘ข๐‘ ๐‘ก๐‘–๐‘“๐‘ฆ-๐‘๐‘œ๐‘›๐‘ก๐‘’๐‘›๐‘ก-๐‘๐‘’๐‘›๐‘ก๐‘’๐‘Ÿ">

<โ„Ž3>๐ต๐‘œ๐‘œ๐‘˜ ๐ฟ๐‘–๐‘ ๐‘ก

<๐‘‘๐‘Ž๐‘ก๐‘Ž-๐‘™๐‘–๐‘ ๐‘ก [๐‘‘๐‘Ž๐‘ก๐‘Ž๐ฟ๐‘–๐‘ ๐‘ก]="" [๐‘‘๐‘Ž๐‘ก๐‘Ž๐‘‡๐‘ฆ๐‘๐‘’]="๐ต๐‘œ๐‘œ๐‘˜" (๐‘œ๐‘›๐ผ๐‘ก๐‘’๐‘š๐ท๐‘’๐‘™๐‘’๐‘ก๐‘’)="๐‘œ๐‘›๐ผ๐‘ก๐‘’๐‘š๐ท๐‘’๐‘™๐‘’๐‘ก๐‘’($๐‘’๐‘ฃ๐‘’๐‘›๐‘ก)">

<๐‘“๐‘œ๐‘œ๐‘ก๐‘’๐‘Ÿ>

#angular #boostrapping #til