Search code examples
javascripthtmlangulartypescriptangular-ng-if

Angular 4 Hide Dropdown on certain pages


I want to hide a Dropdown (it's elements included) on a certain page. I'd do it with a '*ngIf'-request, however I'm not sure about the condition. The router path is '/project' but I can't access it - therefore *ngIf="path==='/project'" won't work. Any ideas on what condition should be used? Or a better solution to the problem.

There also are subpaths like /project/id, on which the Dropdown should be available.


Solution

  • In your component/controller, try something like:

    showDropdown: boolean = false;
    
    ngOnInit() {
          this.showDropdown = path === '/project'
    }
    

    path is maybe a Input-variable of your component?

    @Input
    path: string;
    

    In your HTML-Template, you do something like:

    <div *ngIf="showDropdown">test</div>