How to Convert Bootstrap 4 theme into Angular 4 Layout
source link: https://www.js-tutorials.com/angularjs-tutorial/convert-bootstrap-4-theme-angular-4-layout/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Convert Bootstrap 4 theme into Angular 4 Layout
Angularjs is very popular js framework.This tutorial help to create layout into angular2/4.We will convert our Bootstrap HTML theme into angularjs layout with routes.I am taking sample bootstrap theme that will have header,footer and sidebar.I will convert them into separate partial files and use into master layout to render all portions.
Why do we need layout or theming, Layout help to organised your theme and easy to handle common page HTML content, without layout you can use header,footer and sidebar into each page, that constant HTML code will repeat.You can remove that overhead using layout.
Since, I am using angular 4, so We will create component for each partial files.We will create header, footer and sidebar component and call these component into master layout.
I will use angular CLI to create component and module, like below,
ng create component component_name
ng create module module_name
Angular application structuresrc
: This folder will contain angular all modules and components.src/assets
: This folder will contain all css,fonts and js files.src/app/shared
: This folder will shared module.src/app/shared/layout
: This folder will contain all layout partial components.src/app/shared/layout/footer
: This folder will contain footer component files.src/app/shared/layout/header
: This folder will contain header component files.src/app/shared/layout/sidebar
: This folder will contain sidebar component files.src/app/dashboard
: This folder will contain dashboard component files.
I am taking Bootstrap 4 theme Shop Item.This is very simple shop item page template using Bootstrap.This is open source with MIT type License.
So in this angular 4 layout tutorial, we will use following main files to keep HTML content,
header.component.html
: This file will contain html template header part.sidebar.component.html
: This file will contain html template sidebar part.footer.component.html
: This file will contain html template footer part.layout.component.html
: This file will use to include above partial component files and create layout template which will render on each angular request.dashboard.component.html
: This file will contain dashboard page html content.
Lets create Angular Layout,I assumed you have downloaded bootstrap theme and create new app like below,ng new angular-layout
We will create shared module,$angular-layout/src/app > ng generate module shared
We will create layout module,$angular-layout/src/app/shared > ng generate module layout
$angular-layout/src/app/shared > ng generate component layout
We will create header component,$angular-layout/src/app/shared/layout > ng generate component header
We will create footer module,$angular-layout/src/app/shared/layout > ng generate component footer
We will create sidebar component,$angular-layout/src/app/shared/layout > ng generate component sidebar
We will create dashboard module,$angular-layout/src/app > ng generate module dashboard
$angular-layout/src/app > ng generate component dashboard
Now open angular-layout/.angular-cli.json
file and add third party js into script array like below, if you have,
And add css libs,
Header component in Angular 4 Layout
We will add header HTML element into header component, I will use component.ts
and component.html
file.Open src\app\shared\layout\header\header.component.html
file add below code,
Now open header.component.ts
file and changed below codes.
I have changed selecter values, this refres to layout html container id.
Footer componenet in Angular 4 Layout
We will create footer component into this angularjs layout example, I will modified component.ts
and component.html
files, Open src\app\shared\layout\footer\footer.component.html
file add below code,
Now open footer.component.ts
file and changed below codes.
I have changed selecter values, this refres to layout footer html container id.
Sidebar componenet in Angular4 Layout
We will create sidebar component into this angularjs layout example, I will modified component.ts
and component.html
files, Open src\app\shared\layout\sidebar\sidebar.component.html
file add below code,
Now open footer.component.ts
file and changed below codes.
I have changed selector values, this refers to layout footer html container id.
Layout module
Now create layout/index.ts
file and export all partials components,
Shared module
We will create shared/index.ts
file and export layout component,
Now Open shared/shared.module.ts
and add below code,
Dashboard Module in Angular4 Layout
We will create dashboard component into this angularjs theme example, I will modified component.ts
and component.html files, Open src\app\dashboard\dashboard.component.html
file add below code,
Now open dashboard.module.ts
file and replaced with below codes.
App Component in Angular Layout Example
We have created all partials component and changed html layout, now I will call layout into app root component, open app.componenent.html
file and replace with below code ,
Now we will modified app.module.ts
file and added below code,
Now run ng serve
command to view your layout on http://localhost:4200
.
Conclusion:
I have created Layout using angular4 and bootstrap 4.You can create multiple layout and use into angular app, like for registered and guest user.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK