Skip to content
  • Home
  • Search
  • Tools
  • About
  • Terms of Service Agreement
  • Log In
  • Guest

ANGULAR 10: Step Two – Angular 10/Bootstrap Modules and View Setup

Posted on September 3, 2020July 6, 2023 By Andre Dias
angular, bootstrap, javascript

Back to index 

<Previous   Next >

Code download

IMPORTANT NOTE

The procedures described here details how the application was created.
Follow them if you have created your application from scratch, otherwise it is not necessary since it is already done.

In both cases, the procedures are useful to understand the details.

 

Table of Contents

  • #DOWNLOAD
  • #CREATING MODULE
  • #CREATING THE ANGULAR COMPONENTS
  • #ROUTING
  • #VIEW ADJUSTMENTS
    • #HOW DOES IT WORK?
  • #IMPLEMENTING NAVBAR BOOTSTRAP COMPONENT
    • #REGISTERING THE COMPONENT
      • #Navbar closed
      • #Navbar Opened
  • #IMPLEMENTING STEP TWO PAGE
    • #PAGE DEFAULT CONTENT
    • #IMPLEMENTING STEPTWO PAGE CONTENT USING BOOTSTRAP

#DOWNLOAD

Download the project at Github from “features/step02” branch.

 

#CREATING MODULE

– Create the module for the 1st step denoted by stepone:
ng g module steptwo

 

#CREATING THE ANGULAR COMPONENTS

ng g c home
ng g c steptwo/steptwo

 

– register into app.module.ts:

 

import { SteptwoModule } from ‘./steptwo/steptwo.module’;

imports: [
…
SteptwoModule,
…
]

 

#ROUTING

Edit app-routing.module.ts.

Add as follows:

 

import { SteptwoModule } from './steptwo/steptwo.module';

const routes: Routes = [
  {path: '', component: HomeComponent, pathMatch: 'full'},
  {path: 'steptwo', component: SteptwoComponent},
  {path: '**', component: HomeComponent}
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes),
    SteponeModule,
  ],
  exports: [RouterModule]
})

 

#VIEW ADJUSTMENTS

Copy the index.html file to your project.

Edit app-component.html and replace all the content with just this:

<router-outlet></router-outlet>

#HOW DOES IT WORK?

The application uses the index.html file as starting point — the default configuration.
When pointed to localhost:4200 (or another port), the routing service will redirect to the default address using the router’s empty declaration that points to HomeComponent.

This is configured in the app-routing.module.ts file at:
const routes: Routes = [
  {path: '', component: HomeComponent, pathMatch: 'full'}, // router's empty declaration
   // ...
  {path: '**', component: HomeComponent}  // router's any other declaration
];
Important to highlight that the declaration order of path is important since it is read in sequence.
All other path declarations go between replacing the ellipsis comment.
The HTML’s file of HomeComponent contains the initial page shown by the application, generating the output that it is returned by router’s sevice that renders this content replacing the <router-outlet></router-outlet> elements in app.component.html, and by its turn returns the content that replaces <app-root></app-root> element in the index.html file.

That way, the index.html file contains the common features shared with all the application’s pages.
Similarly, the app.component.html file also shares, but unlike index.html, the app.component.html may add extra processing resources using its app.component.ts file.
When the user clicks a card defined in home.component.html, the routing cycle will be repeated using the chosen path.
Each path maps to its respective module.

#IMPLEMENTING NAVBAR BOOTSTRAP COMPONENT

The home.component.html requires a navbar.

Unfortunately, it is not possible to use Bootstrap’s dynamic features, like opening and closing events, straight from its library.
The first issue that you notice is that navbar fails.
Dynamic features requires Ng-bootstrap behind the scene that it is used to implement a dynamic bootstrap component in the Angular world.

Run the commands to create a component module and its component:

ng g module components

ng g c components/navbar

 

Replace the component module created above replacing it with the respective code from Github from “features/step02” branch.

Why is the component replaced and not just copied?

We need to run the commands to create it because of the additional registering actions performed during this operation, then we may replace contents.

#REGISTERING THE COMPONENT

 

Edit app.module.ts and register the module and the component.
A module is imported and a component decrared.

import { ComponentsModule } from ‘./components/components.module’;
@NgModule({
  declarations: [
    AppComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgbModule,
    SteptwoModule,
    ComponentsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

If the component module is not registered, the selector element is not recognized generating error message.

 

Now edit app.component.html and add the navbar selector:

<app-navbar></app-navbar>
<router-outlet></router-outlet>

Remember that everything added to app.component.html will be shared with all pages.

 

#Navbar closed

 

#Navbar Opened

 

 

#IMPLEMENTING STEP TWO PAGE

 

#PAGE DEFAULT CONTENT

When a component is created, by default you get a “component works” text like shown below.

#IMPLEMENTING STEPTWO PAGE CONTENT USING BOOTSTRAP

 

Now, the easiest part.
To add Bootstrap code is a very simple operation.
In this page, it was used the Jumbotron example from Boostrap site.

The trick is that you copy just part of the code, since the basic structure is already defined by index.html, app.component.html, etc.

Open the steptwo.component.html  at Github from “features/step02” branch and copy its content to past to your project’s page.

Notice that it was used just the new code to be used in the page, discarding the scaffolding code.

This is really good because templates reduce maintenance.

This is the page you get from the tutorial.

 

 

 

Back to index 

<Previous   Next >

 

Andre Dias
Andre Dias

Brazilian system analyst graduated by UNESA (University Estácio de Sá – Rio de Janeiro). Geek by heart.

Post navigation

❮ Previous Post: ANGULAR 10: Step One B – Creating A Local Installation To Preserve Current Environment
Next Post: ANGULAR: Step Zero – How does this tutorial work? ❯

Search

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
angular
bootstrap
browser
computer science
container
data persistence
database
devops
editors
hardware
health
hosting
info
internet
it
java
javascript
network
node.js
play
protocol
security
self-help
selfhelp
server
services
soft
software engeneering
sql
support
Systems
techs
Uncategorized
versioning
web
web design
windows
wordpress

Recent Posts

  • Angular From Scratch Tutorial – Step 9: Modal
  • Angular From Scratch Tutorial – Step 8: Miscellany
  • Angular From Scratch Tutorial – Index
  • angular: Reading JSON files
  • NODE.JS: SEQUELIZE: MVC Project – 4TH STEP

Categories

  • angular (19)
  • bootstrap (6)
  • browser (4)
  • computer science (4)
  • container (1)
  • data persistence (2)
  • database (11)
  • devops (1)
  • editors (1)
  • hardware (4)
  • health (2)
  • hosting (1)
  • info (1)
  • internet (2)
  • it (1)
  • java (13)
  • javascript (32)
  • network (6)
  • node.js (1)
  • play (1)
  • protocol (1)
  • security (4)
  • self-help (1)
  • selfhelp (1)
  • server (2)
  • services (1)
  • soft (1)
  • software engeneering (1)
  • sql (1)
  • support (2)
  • Systems (1)
  • techs (3)
  • Uncategorized (2)
  • versioning (6)
  • web (1)
  • web design (5)
  • windows (3)
  • wordpress (4)

Copyright © 2025 .

Theme: Oceanly by ScriptsTown

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT