Why ng-content selector is not working inside *ngFor

前端 未结 6 1116
梦如初夏
梦如初夏 2020-12-21 18:06

Here is the stackblitz code.

As you can see

6条回答
  •  余生分开走
    2020-12-21 18:53

    You cannot do this, without two loops. The reason being ng-content is a placeholder, which accepts dynamic html inside. Now when you loop inside your code, you don't assign anything to the even or odd selector. But if you change your code to below

    
        
      {{number}}
      {{number}}

    You will see the output change to

    This is because no the output of ng-For has been assigned to the even selector.

    If you change the template to below

    
        
      {{number}}
      {{number}}

    It will work

    Also remember inside a ng-For you cannot append content to a even or odd section, even if that feature was available it would have overwritten the section with the last value.

    Leaving even ng-for out of it. The below code

    
      
    This should be under odd

    Also won't work

    So what you are trying to achieve and the way you are trying to achieve it is not supported by angular.

提交回复
热议问题