unable to remove empty tag using angular 6





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







3















Here I am having a issue below is my json data



 data = {
"required": false,
"name": "data",
"details": [
{
"name": "type",
"details": {
"visible": false,

}
},
{
"name": "Creation",
"details": {

"visible":true,

}
},
{
"name": "Creation",
"details": {

"visible": false,

}
},

{
"name": "Modification",
"details": {

"visible": true,

}
}

]
}


.html code



<ng-container *ngFor="let x of data.details">
<ul>
<li *ngIf="x.details.visible">
{{x.name}}
</li>
</ul>
</ng-container>


The issue here is even though I condition is true here it is creating empty tags by this my html style is getting disturbed and getting unwanted spaces



in the console it showed me like this



<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Creation </li></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Modification</li></ul>


How can I remove that empty spaces.



Below is my stack blitz URL.



https://stackblitz.com/edit/angular-yw2zy5










share|improve this question




















  • 1





    Move the *ngIf to the ul tag.

    – rrd
    Nov 23 '18 at 8:17











  • use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

    – xyz
    Nov 23 '18 at 8:17











  • @AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

    – techie
    Nov 23 '18 at 8:23











  • @techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

    – Sanoj_V
    Nov 23 '18 at 8:24




















3















Here I am having a issue below is my json data



 data = {
"required": false,
"name": "data",
"details": [
{
"name": "type",
"details": {
"visible": false,

}
},
{
"name": "Creation",
"details": {

"visible":true,

}
},
{
"name": "Creation",
"details": {

"visible": false,

}
},

{
"name": "Modification",
"details": {

"visible": true,

}
}

]
}


.html code



<ng-container *ngFor="let x of data.details">
<ul>
<li *ngIf="x.details.visible">
{{x.name}}
</li>
</ul>
</ng-container>


The issue here is even though I condition is true here it is creating empty tags by this my html style is getting disturbed and getting unwanted spaces



in the console it showed me like this



<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Creation </li></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Modification</li></ul>


How can I remove that empty spaces.



Below is my stack blitz URL.



https://stackblitz.com/edit/angular-yw2zy5










share|improve this question




















  • 1





    Move the *ngIf to the ul tag.

    – rrd
    Nov 23 '18 at 8:17











  • use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

    – xyz
    Nov 23 '18 at 8:17











  • @AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

    – techie
    Nov 23 '18 at 8:23











  • @techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

    – Sanoj_V
    Nov 23 '18 at 8:24
















3












3








3








Here I am having a issue below is my json data



 data = {
"required": false,
"name": "data",
"details": [
{
"name": "type",
"details": {
"visible": false,

}
},
{
"name": "Creation",
"details": {

"visible":true,

}
},
{
"name": "Creation",
"details": {

"visible": false,

}
},

{
"name": "Modification",
"details": {

"visible": true,

}
}

]
}


.html code



<ng-container *ngFor="let x of data.details">
<ul>
<li *ngIf="x.details.visible">
{{x.name}}
</li>
</ul>
</ng-container>


The issue here is even though I condition is true here it is creating empty tags by this my html style is getting disturbed and getting unwanted spaces



in the console it showed me like this



<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Creation </li></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Modification</li></ul>


How can I remove that empty spaces.



Below is my stack blitz URL.



https://stackblitz.com/edit/angular-yw2zy5










share|improve this question
















Here I am having a issue below is my json data



 data = {
"required": false,
"name": "data",
"details": [
{
"name": "type",
"details": {
"visible": false,

}
},
{
"name": "Creation",
"details": {

"visible":true,

}
},
{
"name": "Creation",
"details": {

"visible": false,

}
},

{
"name": "Modification",
"details": {

"visible": true,

}
}

]
}


.html code



<ng-container *ngFor="let x of data.details">
<ul>
<li *ngIf="x.details.visible">
{{x.name}}
</li>
</ul>
</ng-container>


The issue here is even though I condition is true here it is creating empty tags by this my html style is getting disturbed and getting unwanted spaces



in the console it showed me like this



<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Creation </li></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></ul>

<ul _ngcontent-c76=""><!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c76=""> Modification</li></ul>


How can I remove that empty spaces.



Below is my stack blitz URL.



https://stackblitz.com/edit/angular-yw2zy5







javascript angular typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:43







techie

















asked Nov 23 '18 at 8:14









techietechie

188




188








  • 1





    Move the *ngIf to the ul tag.

    – rrd
    Nov 23 '18 at 8:17











  • use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

    – xyz
    Nov 23 '18 at 8:17











  • @AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

    – techie
    Nov 23 '18 at 8:23











  • @techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

    – Sanoj_V
    Nov 23 '18 at 8:24
















  • 1





    Move the *ngIf to the ul tag.

    – rrd
    Nov 23 '18 at 8:17











  • use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

    – xyz
    Nov 23 '18 at 8:17











  • @AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

    – techie
    Nov 23 '18 at 8:23











  • @techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

    – Sanoj_V
    Nov 23 '18 at 8:24










1




1





Move the *ngIf to the ul tag.

– rrd
Nov 23 '18 at 8:17





Move the *ngIf to the ul tag.

– rrd
Nov 23 '18 at 8:17













use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

– xyz
Nov 23 '18 at 8:17





use the ngIf condition in your ul. BTW you want so many uls? or one ul and many lis?

– xyz
Nov 23 '18 at 8:17













@AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

– techie
Nov 23 '18 at 8:23





@AshishRanjan the uls & lis are generated depending on my data if the visible is false it shouldnt display but here if it is false then it is displaying empty tags

– techie
Nov 23 '18 at 8:23













@techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

– Sanoj_V
Nov 23 '18 at 8:24







@techie look at this post Delete comments of DOM for *ngFor and *ngIf in Angular

– Sanoj_V
Nov 23 '18 at 8:24














2 Answers
2






active

oldest

votes


















0














You should change your template to following



<ul>
<ng-container *ngFor="let x of data.details">
<li *ngIf="x.details.visible">
{{x.name}}
</li>
</ng-container>
</ul>


You would not want to have bunch of ul with single li elements. What the code above will do is to create a single ul and add some li elements within if x.details.visible condition is met






share|improve this answer































    2














    Issues with your implementation:




    1. You have *ngFor on the ul instead of the li. That is making the ul getting repeated on the DOM and thus breaking your style.

    2. You should be using the ng-container as a parent of the li instead of using it as a parent to the ul. That way, you will be able to add the *ngIf condition on the li while using *ngFor on the ng-container.


    Give this a try:



    <hello name="{{ name }}"></hello>
    <ul>
    <ng-container *ngFor="let x of data.details">
    <li *ngIf="x.details.visible">
    {{x.name}}
    </li>
    </ng-container>
    </ul>




    Here's a Sample StackBlitz for your ref.






    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%2f53442847%2funable-to-remove-empty-tag-using-angular-6%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














      You should change your template to following



      <ul>
      <ng-container *ngFor="let x of data.details">
      <li *ngIf="x.details.visible">
      {{x.name}}
      </li>
      </ng-container>
      </ul>


      You would not want to have bunch of ul with single li elements. What the code above will do is to create a single ul and add some li elements within if x.details.visible condition is met






      share|improve this answer




























        0














        You should change your template to following



        <ul>
        <ng-container *ngFor="let x of data.details">
        <li *ngIf="x.details.visible">
        {{x.name}}
        </li>
        </ng-container>
        </ul>


        You would not want to have bunch of ul with single li elements. What the code above will do is to create a single ul and add some li elements within if x.details.visible condition is met






        share|improve this answer


























          0












          0








          0







          You should change your template to following



          <ul>
          <ng-container *ngFor="let x of data.details">
          <li *ngIf="x.details.visible">
          {{x.name}}
          </li>
          </ng-container>
          </ul>


          You would not want to have bunch of ul with single li elements. What the code above will do is to create a single ul and add some li elements within if x.details.visible condition is met






          share|improve this answer













          You should change your template to following



          <ul>
          <ng-container *ngFor="let x of data.details">
          <li *ngIf="x.details.visible">
          {{x.name}}
          </li>
          </ng-container>
          </ul>


          You would not want to have bunch of ul with single li elements. What the code above will do is to create a single ul and add some li elements within if x.details.visible condition is met







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 8:23









          Bunyamin CoskunerBunyamin Coskuner

          4,17011136




          4,17011136

























              2














              Issues with your implementation:




              1. You have *ngFor on the ul instead of the li. That is making the ul getting repeated on the DOM and thus breaking your style.

              2. You should be using the ng-container as a parent of the li instead of using it as a parent to the ul. That way, you will be able to add the *ngIf condition on the li while using *ngFor on the ng-container.


              Give this a try:



              <hello name="{{ name }}"></hello>
              <ul>
              <ng-container *ngFor="let x of data.details">
              <li *ngIf="x.details.visible">
              {{x.name}}
              </li>
              </ng-container>
              </ul>




              Here's a Sample StackBlitz for your ref.






              share|improve this answer




























                2














                Issues with your implementation:




                1. You have *ngFor on the ul instead of the li. That is making the ul getting repeated on the DOM and thus breaking your style.

                2. You should be using the ng-container as a parent of the li instead of using it as a parent to the ul. That way, you will be able to add the *ngIf condition on the li while using *ngFor on the ng-container.


                Give this a try:



                <hello name="{{ name }}"></hello>
                <ul>
                <ng-container *ngFor="let x of data.details">
                <li *ngIf="x.details.visible">
                {{x.name}}
                </li>
                </ng-container>
                </ul>




                Here's a Sample StackBlitz for your ref.






                share|improve this answer


























                  2












                  2








                  2







                  Issues with your implementation:




                  1. You have *ngFor on the ul instead of the li. That is making the ul getting repeated on the DOM and thus breaking your style.

                  2. You should be using the ng-container as a parent of the li instead of using it as a parent to the ul. That way, you will be able to add the *ngIf condition on the li while using *ngFor on the ng-container.


                  Give this a try:



                  <hello name="{{ name }}"></hello>
                  <ul>
                  <ng-container *ngFor="let x of data.details">
                  <li *ngIf="x.details.visible">
                  {{x.name}}
                  </li>
                  </ng-container>
                  </ul>




                  Here's a Sample StackBlitz for your ref.






                  share|improve this answer













                  Issues with your implementation:




                  1. You have *ngFor on the ul instead of the li. That is making the ul getting repeated on the DOM and thus breaking your style.

                  2. You should be using the ng-container as a parent of the li instead of using it as a parent to the ul. That way, you will be able to add the *ngIf condition on the li while using *ngFor on the ng-container.


                  Give this a try:



                  <hello name="{{ name }}"></hello>
                  <ul>
                  <ng-container *ngFor="let x of data.details">
                  <li *ngIf="x.details.visible">
                  {{x.name}}
                  </li>
                  </ng-container>
                  </ul>




                  Here's a Sample StackBlitz for your ref.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 8:21









                  SiddAjmeraSiddAjmera

                  16.3k31240




                  16.3k31240






























                      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%2f53442847%2funable-to-remove-empty-tag-using-angular-6%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

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?