2

hello Everyone I want to add default layout to be the main layout of all my angular components ,

eg. Layout for main pages and layout for login pages. If it is available to make that? If not , what is the best way to handle this matter?

Ahmed Sakr
  • 129
  • 1
  • 9

2 Answers2

3

This can be achieved in atleast 2 ways:

Good luck!

Jelle
  • 2,026
  • 1
  • 12
  • 17
  • Great, but can you provide a full example please? – Ahmed Sakr Jan 21 '19 at 21:56
  • I have provided links to the official documentation with examples and to a stack overflow thread which explains with examples both scenarios. This should help you get started. If you have problems implementing show your implementation so we can help you further – Jelle Jan 21 '19 at 21:58
1

You can do it by define <layout> component (which will use <ng-content>) which will be used by all components in this way

Some component template:

<layout>
    <div> Some component content... </div>
</layout> 

The layout component template can look like that as very simple example (you need to add it to app.module.ts as any other component):

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

@Component({
    selector: 'layout',
    providers: [],
    styleUrls: [ './layout.component.css' ],
    templateUrl: './layout.component.html'
})

export class LayoutComponent implements OnInit
{    
    
    constructor()
    {}

    public ngOnInit()
    {        
        
    }
}
.layout {}
.layout-head {}
.layout-body{}
.layout-footer{}
<div class="layout">
    <div class="layout-head"></div>
    <div class="layout-body">
        <ng-content></ng-content>
    </div>
    <div class="layout-footer"></div>
</div>
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345