0
votes

I developed a component in which I implemented a toolbar. There are several buttons in this toolbar, is there a way to change these buttons when I call this component on another page?

Component name

<app-toolbar></app-toolbar>

Component.html

   <nav class="navbar">
      <ul class="nav">
        <li class="nav-item btn-upload" routerLinkActive="active" [routerLink]="['/upload']">
          <a class="Mais">
            <img src="assets/mais.svg" />
          </a>
          Upload Files
        </li>
      </ul>
    </nav>

For example, can I hide the upload files button and show another button when this component is on another page, for example on the / home page?

1

1 Answers

1
votes

The simplest way to do this is by using ngIf in your app-toolbar template:

toolbar.component.ts

@Input() showUploadBtn: boolean = false;
@Input() showOtherBtn: boolean = false;

toolbar.component.html

<nav class="navbar">
  <ul class="nav">
    <li *ngIf="showUploadBtn" class="nav-item btn-upload" routerLinkActive="active" [routerLink]="['/upload']">
      <a class="Mais">
        <img src="assets/mais.svg" />
      </a>
      Upload Files
    </li>

    <li *ngIf="showOtherBtn">
      <button>Hi</button>
    </li>
  </ul>
</nav>

component1.component.html

<app-toolbar [showUploadBtn]="true"></app-toolbar>

component2.component.html

<app-toolbar [showOtherBtn]="true"></app-toolbar>