Show/hide link with angular












-1















I have two links. ANd I want to show the link if portfolios.length === 0"



And the other link if portfolios.length > 0".



I try it like this:



<p *ngIf="portfolios.length === 0" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
<a>{{resources.dashboardUwPortfolio}} </a>
<a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
</p>


So this is one link:



[attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
<a>{{resources.dashboardUwPortfolio}}


and this is the second link:



<a  [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>


But now both links are visible.



Thank you



I have it like this:



 <p [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
<a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
<a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
</p>









share|improve this question





























    -1















    I have two links. ANd I want to show the link if portfolios.length === 0"



    And the other link if portfolios.length > 0".



    I try it like this:



    <p *ngIf="portfolios.length === 0" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
    <a>{{resources.dashboardUwPortfolio}} </a>
    <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
    </p>


    So this is one link:



    [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
    <a>{{resources.dashboardUwPortfolio}}


    and this is the second link:



    <a  [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>


    But now both links are visible.



    Thank you



    I have it like this:



     <p [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
    <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
    <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
    </p>









    share|improve this question



























      -1












      -1








      -1








      I have two links. ANd I want to show the link if portfolios.length === 0"



      And the other link if portfolios.length > 0".



      I try it like this:



      <p *ngIf="portfolios.length === 0" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a>{{resources.dashboardUwPortfolio}} </a>
      <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
      </p>


      So this is one link:



      [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a>{{resources.dashboardUwPortfolio}}


      and this is the second link:



      <a  [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>


      But now both links are visible.



      Thank you



      I have it like this:



       <p [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
      <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
      </p>









      share|improve this question
















      I have two links. ANd I want to show the link if portfolios.length === 0"



      And the other link if portfolios.length > 0".



      I try it like this:



      <p *ngIf="portfolios.length === 0" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a>{{resources.dashboardUwPortfolio}} </a>
      <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
      </p>


      So this is one link:



      [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a>{{resources.dashboardUwPortfolio}}


      and this is the second link:



      <a  [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>


      But now both links are visible.



      Thank you



      I have it like this:



       <p [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
      <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
      <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
      </p>






      angular






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 14:15







      Coder

















      asked Nov 13 '18 at 13:45









      CoderCoder

      32




      32
























          2 Answers
          2






          active

          oldest

          votes


















          0














          The issue is your structure directive needs to target what you want to hide/show.
          You should also define the show condition for the other url.



          <p [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
          <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
          <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
          </p>





          share|improve this answer
























          • Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

            – Coder
            Nov 13 '18 at 13:59











          • make it an a tag?

            – Mike Tung
            Nov 13 '18 at 14:00











          • Yes, but where ?

            – Coder
            Nov 13 '18 at 14:13











          • oke, got it. Thank you!

            – Coder
            Nov 13 '18 at 14:30



















          0














          A conditional with else attached and an <ng-template> tag might be the cleanest method. You define one condition with an else like this:



          <span *ngIf="portfolios.length === 0; else otherLink">
          {{resources.dashboardUwPortfolio}}
          </span>


          And then, you add to your template the <ng-template> portion with an anchor to otherLink.



          <ng-template #otherLink>
          <span>
          <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
          </span>
          </ng-template>


          The former displays if the condition is true, the latter if not.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282428%2fshow-hide-link-with-angular%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The issue is your structure directive needs to target what you want to hide/show.
            You should also define the show condition for the other url.



            <p [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
            <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
            <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
            </p>





            share|improve this answer
























            • Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

              – Coder
              Nov 13 '18 at 13:59











            • make it an a tag?

              – Mike Tung
              Nov 13 '18 at 14:00











            • Yes, but where ?

              – Coder
              Nov 13 '18 at 14:13











            • oke, got it. Thank you!

              – Coder
              Nov 13 '18 at 14:30
















            0














            The issue is your structure directive needs to target what you want to hide/show.
            You should also define the show condition for the other url.



            <p [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
            <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
            <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
            </p>





            share|improve this answer
























            • Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

              – Coder
              Nov 13 '18 at 13:59











            • make it an a tag?

              – Mike Tung
              Nov 13 '18 at 14:00











            • Yes, but where ?

              – Coder
              Nov 13 '18 at 14:13











            • oke, got it. Thank you!

              – Coder
              Nov 13 '18 at 14:30














            0












            0








            0







            The issue is your structure directive needs to target what you want to hide/show.
            You should also define the show condition for the other url.



            <p [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
            <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
            <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
            </p>





            share|improve this answer













            The issue is your structure directive needs to target what you want to hide/show.
            You should also define the show condition for the other url.



            <p [attr.data-resource-key]="resourceKeys.dashboardUwPortfolio">
            <a *ngIf="portfolios.length === 0">{{resources.dashboardUwPortfolio}}</a>
            <a *ngIf="portfolios.length !== 0" [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
            </p>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 '18 at 13:49









            Mike TungMike Tung

            3,1041714




            3,1041714













            • Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

              – Coder
              Nov 13 '18 at 13:59











            • make it an a tag?

              – Mike Tung
              Nov 13 '18 at 14:00











            • Yes, but where ?

              – Coder
              Nov 13 '18 at 14:13











            • oke, got it. Thank you!

              – Coder
              Nov 13 '18 at 14:30



















            • Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

              – Coder
              Nov 13 '18 at 13:59











            • make it an a tag?

              – Mike Tung
              Nov 13 '18 at 14:00











            • Yes, but where ?

              – Coder
              Nov 13 '18 at 14:13











            • oke, got it. Thank you!

              – Coder
              Nov 13 '18 at 14:30

















            Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

            – Coder
            Nov 13 '18 at 13:59





            Thank you. Very nice but how to make the link resources.dashboardUwPortfolio clickable?

            – Coder
            Nov 13 '18 at 13:59













            make it an a tag?

            – Mike Tung
            Nov 13 '18 at 14:00





            make it an a tag?

            – Mike Tung
            Nov 13 '18 at 14:00













            Yes, but where ?

            – Coder
            Nov 13 '18 at 14:13





            Yes, but where ?

            – Coder
            Nov 13 '18 at 14:13













            oke, got it. Thank you!

            – Coder
            Nov 13 '18 at 14:30





            oke, got it. Thank you!

            – Coder
            Nov 13 '18 at 14:30













            0














            A conditional with else attached and an <ng-template> tag might be the cleanest method. You define one condition with an else like this:



            <span *ngIf="portfolios.length === 0; else otherLink">
            {{resources.dashboardUwPortfolio}}
            </span>


            And then, you add to your template the <ng-template> portion with an anchor to otherLink.



            <ng-template #otherLink>
            <span>
            <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
            </span>
            </ng-template>


            The former displays if the condition is true, the latter if not.






            share|improve this answer




























              0














              A conditional with else attached and an <ng-template> tag might be the cleanest method. You define one condition with an else like this:



              <span *ngIf="portfolios.length === 0; else otherLink">
              {{resources.dashboardUwPortfolio}}
              </span>


              And then, you add to your template the <ng-template> portion with an anchor to otherLink.



              <ng-template #otherLink>
              <span>
              <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
              </span>
              </ng-template>


              The former displays if the condition is true, the latter if not.






              share|improve this answer


























                0












                0








                0







                A conditional with else attached and an <ng-template> tag might be the cleanest method. You define one condition with an else like this:



                <span *ngIf="portfolios.length === 0; else otherLink">
                {{resources.dashboardUwPortfolio}}
                </span>


                And then, you add to your template the <ng-template> portion with an anchor to otherLink.



                <ng-template #otherLink>
                <span>
                <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
                </span>
                </ng-template>


                The former displays if the condition is true, the latter if not.






                share|improve this answer













                A conditional with else attached and an <ng-template> tag might be the cleanest method. You define one condition with an else like this:



                <span *ngIf="portfolios.length === 0; else otherLink">
                {{resources.dashboardUwPortfolio}}
                </span>


                And then, you add to your template the <ng-template> portion with an anchor to otherLink.



                <ng-template #otherLink>
                <span>
                <a [routerLink]="portfolioRoute" [attr.data-resource-key]="resourceKeys.portfolioDashboardAlleLink"> {{resources.portfolioDashboardAlleLink}}</a>
                </span>
                </ng-template>


                The former displays if the condition is true, the latter if not.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 14:23









                BytechBytech

                364213




                364213






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282428%2fshow-hide-link-with-angular%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine