0

I have a directive that I want to add to div but only if the user is on a particular page. The code below shows the directive but I want it to be only added if that page is as follows in the second snippet - I have the variable selectedSection that will provide me with page the user is on

// my html code

<div class="dynamic-tabs" prompt="manage">

// my pseudocode

if (selectedSection == 'admin') then add the 'prompt="manage" directive

Alexander Abakumov
  • 12,301
  • 14
  • 79
  • 125
Zabs
  • 13,252
  • 42
  • 158
  • 277
  • 2
    Note: that dupe link was the ___first___ google search result, from searching the exact title of this question. Zabs, please do your research before asking. – Cerbrus Sep 06 '17 at 11:26
  • 2
    I think he is asking for angular not angularjs. it looks like you marked duplicate with the link to angularjs. note that angular and angularjs are two entirely different framework – Aniruddha Das Sep 06 '17 at 11:28
  • Note: the second dupe link was the _first_ google search result, from searching the exact title of this question + "2". Zabs, please do your research before asking. – Cerbrus Sep 06 '17 at 11:30
  • @AniruddhaDas: The same comment still applies. Search before asking. – Cerbrus Sep 06 '17 at 11:31
  • 1
    Rather a dup of https://stackoverflow.com/questions/45084292/dynamically-mount-angular-2-directive/45324407#45324407 or https://stackoverflow.com/questions/37021355/angular-2-how-to-conditionally-apply-attribute-directive/37022051#37022051 – Günter Zöchbauer Sep 06 '17 at 11:31
  • @GünterZöchbauer: Feel free to add the links. – Cerbrus Sep 06 '17 at 11:32
  • @Cerbrus can you please reopen, this is Angular 2 and the other is Angular JS. I don't know if I can reopen **and** mark as duplicate (AFAIK there is a limitation). – Günter Zöchbauer Sep 06 '17 at 11:36
  • 1
    @GünterZöchbauer: You have a gold badge in some of the tags here, you should be able to just change the links (Bottom-right of the yellow "duplicate" block) – Cerbrus Sep 06 '17 at 11:38
  • 1
    @Cerbrus thanks a lot! Never noticed before that I can edit there :D – Günter Zöchbauer Sep 06 '17 at 11:39
  • @Cerbrus, I think the angularjs link need to be removed. the user will confused with angular. – Aniruddha Das Sep 06 '17 at 14:34

1 Answers1

0

What about an *ngIf condition? (or ng-if with Angular 1)

<div class="dynamic-tabs" prompt="manage" *ngIf="selectedSection === 'admin'"> </div>

<div class="dynamic-tabs" *ngIf="selectedSection !== 'admin'"> </div>
Jeremy Thille
  • 25,196
  • 9
  • 41
  • 59