M
M
mr_plutus2016-09-20 13:27:14
Angular
mr_plutus, 2016-09-20 13:27:14

How to enable or disable a block on a page?

Good afternoon.
Question on the second angular.
There is a main component app.component
In it is a template:

<header class="header"></header>
<aside class="aside"></aside>
<router-outlet></router-outlet>

How to hide aside or header on other pages if they are not required there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antkhnvsk, 2016-09-23
@mr_plutus

In the template itself, write ngIf

<header *ngIf="hasHeader" class="header"></header>
<aside *ngIf="hasAside" class="aside"></aside>
<router-outlet></router-outlet>

Listening for router changes in app.component
import {Router} from '@angular/router';
export class AppComponent {
  hasHeader: boolean = true
  hasAside: boolean = true

  constructor(
    private _router: Router
  ) { }

  ngOnInit() {
    this._router.events
      .subscribe(params => {
        let path = params.url.split('/')[1]
        if (path == 'auth') {
          this.hasHeader = false
          this.hasAside = false
        } else {
          this.hasHeader = true
          this.hasAside = true
        }
      })
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question