<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Angular Barrack]]></title><description><![CDATA[Let's get into the world of angular by going through each topic and make every hard concept easier.]]></description><link>https://angular-barrack.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/64e6f917d6f2510f582ba636/7ae4c4f5-3df3-442d-8813-c29ea998e003.jpg</url><title>Angular Barrack</title><link>https://angular-barrack.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 08:27:59 GMT</lastBuildDate><atom:link href="https://angular-barrack.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Angular Components]]></title><description><![CDATA[Components are a key feature in angular, multiple small components together make up the whole application.
AppComponent is the root component which holds entire application think of it like a big cont]]></description><link>https://angular-barrack.hashnode.dev/angular-components</link><guid isPermaLink="true">https://angular-barrack.hashnode.dev/angular-components</guid><dc:creator><![CDATA[Sanskar jain]]></dc:creator><pubDate>Sat, 22 Aug 2026 13:21:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/00d79cb2-b2fd-4f27-9a81-730a905c0970.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Components are a key feature in angular, multiple small components together make up the whole application.</p>
<p>AppComponent is the root component which holds entire application think of it like a big container which keeps other components in it.</p>
<p>The @Component Decorator is used for declaring the component.</p>
<h3>How do we create a component?</h3>
<p>So in the app folder there is the app component which is also the component we use to bootstrap the whole application meaning this component is used as a starting point or lets say container for the whole application.</p>
<p>Note:- Since we already included the AppComponent in the bootstrap array of the AppModule we cannot add any other thing in it.</p>
<pre><code class="language-plaintext">import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }
</code></pre>
<p>In the directory we create all other components in the app folder since the AppComponent will be the parent component component of all other components it is only natural we place the folders of other components inside the app folder.</p>
<pre><code class="language-plaintext">import { Component } from "@angular/core";

@Component({
    selector: 'app-server',
    templateUrl: './server.component.html'
})
export class ServerComponent {
}
</code></pre>
<p>We declare typescript classes in a component which are treated as component when we add the @Component Decorator on them.</p>
<p>The @Component we need to import it from the anguar/core so that it known to typescript so that when it parses this file and compiles to javascript it is able to understand it.</p>
<p>We passed a javascript object to the component decorator to configure it as without any configuration it is not valuable to angular.</p>
<p>So we have set up some important configuration which will be stored as metadata for this class in the background which will tell angular what to do with this class.</p>
<p>So we have set up two important piece of information here,</p>
<h4>1. Selector:</h4>
<p>Selector is a unique name or ID which we give to our component. This selector is used in other component html files as tag to include them.</p>
<h4>2. TemplateUrl:</h4>
<p>The template is a .html file which the component references, in this .html we write all the content content which we want to display in the browser also we include other components in this. Note:- It requires a relative path for this as all of this will be bundled by webpack in the end so we need to tell it where to find the file.</p>
<h3>How to use the component?</h3>
<p>In order to use the Component you need to include it in the declarations array of the app module so that it angular registers it with the module meaning it tells angular that this component is now being managed by this module.</p>
<pre><code class="language-plaintext">import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';
  
@NgModule({
  declarations: [
    AppComponent,
    ServerComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
</code></pre>
<p>Here you can we imported our ServerComponent and then included it in the declarations array in order to register it in our module.</p>
<p>Now the angular knows about this component that it is being managed by this module so we can now include it in other components.</p>
<pre><code class="language-plaintext">&lt;h1&gt;Hello world!&lt;/h1&gt;
&lt;app-server&gt;&lt;/app-server&gt;
</code></pre>
<p>This is app.component.html see we used the selector of ServerComponent to include it.</p>
<p>Now, if you start the application you will see the content of both AppComponent and ServerComponent.</p>
<p>![[Pasted image 20260821074338.png]](<a href="https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/36f189bc-da0f-4864-9192-cc37f01a3fc0.png">https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/36f189bc-da0f-4864-9192-cc37f01a3fc0.png</a> align="center")</p>
<h3>Creating Components with CLI and Nested Components</h3>
<p>Instead of manually making components the angular cli allows us to use commands to generate the components one such command is:</p>
<pre><code class="language-plaintext">ng generate component component-name
ng g c component-name //shortcut for the same command
</code></pre>
<p>This is the command lets us generate the component folder with all the required files in it.</p>
<p>It generates -&gt; component-name.component.html, .ts, .css and .spec (this is for testing).</p>
<p>for example: Lets create a component NestedServer.</p>
<pre><code class="language-plaintext">ng generate component nestedserver
</code></pre>
<p>It will create the folder and files inside the folder.</p>
<p>![[Pasted image 20260821172907.png|264]](<a href="https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/cf0ba753-b57f-469e-be84-bf28d3d0f817.png">https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/cf0ba753-b57f-469e-be84-bf28d3d0f817.png</a> align="left")</p>
<p>When you generate it using CLI it also includes it automatically inside the module's declarations array so that it gets registered in the angular and get managed by module.</p>
<p>You can nest the components in other components also for example lets include this component in the ServerComponent.</p>
<pre><code class="language-plaintext">&lt;h1&gt;The server component&lt;/h1&gt;
&lt;app-nestedserver&gt;&lt;/app-nestedserver&gt;
</code></pre>
<p>This is the server.component.html file, you will see it on the browser like this</p>
<p>![[Pasted image 20260821182926.png]](<a href="https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/ef6f12c5-08e3-48b6-ab11-45f87dea04ac.png">https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/ef6f12c5-08e3-48b6-ab11-45f87dea04ac.png</a> align="center")</p>
<p>This is all about the components for now in this blog.</p>
<p>See you in the next blog.</p>
]]></content:encoded></item><item><title><![CDATA[How an Angular app gets loaded and started]]></title><description><![CDATA[Many people who just started with angular may think that as we do the changes in the app component then the app component must be the one which is getting served by the server.
But that is not the cas]]></description><link>https://angular-barrack.hashnode.dev/how-an-angular-app-gets-loaded-and-started</link><guid isPermaLink="true">https://angular-barrack.hashnode.dev/how-an-angular-app-gets-loaded-and-started</guid><dc:creator><![CDATA[Sanskar jain]]></dc:creator><pubDate>Sun, 16 Aug 2026 18:09:52 GMT</pubDate><content:encoded><![CDATA[<p>Many people who just started with angular may think that as we do the changes in the app component then the app component must be the one which is getting served by the server.</p>
<p>But that is not the case in angular the file which gets served by the server is the index.html file.</p>
<p>Angular is the framework which allows us to create single page application and the index.html is exactly that single page which we are talking about here.</p>
<p>this is how the index.html file looks like</p>
<pre><code class="language-html">&lt;!doctype html&gt;

&lt;html lang="en"&gt;

&lt;head&gt;

  &lt;meta charset="utf-8"&gt;

  &lt;title&gt;ProjectTemplate&lt;/title&gt;

  &lt;base href="/"&gt;

  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;

  &lt;link rel="icon" type="image/x-icon" href="favicon.ico"&gt;

&lt;/head&gt;

&lt;body&gt;

  &lt;app-root&gt;&lt;/app-root&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>
<p>Notice the <code>&lt;app-root&gt;&lt;/app-root&gt;</code> there is nothing in between it but our application is still showing the text "Hello World!" which we written app.component.html.</p>
<p>To understand it lets take a look at app.component.ts file</p>
<pre><code class="language-typescript">import { Component } from '@angular/core';

@Component({

  selector: 'app-root',

  templateUrl: './app.component.html',

  styleUrls: ['./app.component.css']

})

export class AppComponent {

}
</code></pre>
<p>Notice the selector, in this the app-root is the same as the one mentioned in index.html.</p>
<p>The framework essentially replaces the app-root with our app component that's why you see the content which was written in the app.component.html in the browser.</p>
<p>Though we know why it is showing the content of the app component but we still need to figure out how angular is triggered when we changed something.</p>
<h2>How angular is triggered?</h2>
<p>So in the final index.html (you can see it by inspecting the source in the browser) there are a couple of scripts attached.</p>
<p>![[Pasted image 20260816193752.png]](<a href="https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/3a4063d8-73f2-4518-ac1f-fa7e66f77694.png">https://cdn.hashnode.com/uploads/covers/64e6f917d6f2510f582ba636/3a4063d8-73f2-4518-ac1f-fa7e66f77694.png</a> align="center")</p>
<p>These are injected by the CLI automatically.</p>
<p>In the raw index.html file we don't have any imports but whenever ng serve rebuilds our project, it will create javascript bundles and automatically add the right imports in the index.html file.</p>
<p>Now, the first code which gets executed is the main.ts file's code.</p>
<h4>The main.ts file:-</h4>
<pre><code class="language-typescript">import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';


platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err =&gt; console.error(err));
</code></pre>
<p>This is the code which gets executed first it contains some imports but the main code is the last line <code>platformBrowserDynamic().bootstrapModule(AppModule).catch(err =&gt; console.error(err));</code> this line is the which bootstraps/starts our angular application by passing the AppModule to the function.</p>
<p>Now lets take a closer look at the AppModule.</p>
<h4>The app.module.ts file:-</h4>
<pre><code class="language-typescript">import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

  

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

export class AppModule { }
</code></pre>
<p>Here, you will see a lot of things we for now what you need to focus on is the bootstrap array, this array list all the components which should be known to angular at the time it analyzes the index.html file.</p>
<p>We passed our AppComponent in this array, so by this you may guess how changing in the AppComponent reflects the change in our browser.</p>
<p>The flow is somewhat like this, AppComponent -&gt; AppModule (Bootstrap Array) -&gt; main.ts (includes the AppModule) -&gt; ng serve (bundles the code and attaches scripts the index.html) -&gt; Index.html finds the app-root selector and replaces it with the app component -&gt; final index.html (where the compiled main.js file is attached using a script tag).</p>
<p>Note:- If we didn't have included the AppComponent in the AppModule's bootstrap array then the index.html file would not have been able to find it. Think of it like, index.html or whichever file finds whatever written in it in a room and the one places things in that room is the bootstrap array.</p>
<p>That is all on how a angular app gets loaded and started.</p>
<p>See you again in next blog 👋.</p>
]]></content:encoded></item></channel></rss>