简体   繁体   English

*ngFor Inside *ngIf - 如何正确重写

[英]*ngFor Inside *ngIf - How to Rewrite it properly

could some one tell me how to rewrite below *ngIF and *ngFor combination.?有人可以告诉我如何在 *ngIF 和 *ngFor 组合下面重写。?

I'm aware about my issue is duplicate but pls understand, this is different.我知道我的问题是重复的,但请理解,这是不同的。

it's working as fine.它工作得很好。 but issue what am facing is that <li></li> tag color is not getting changed dynamically.但我面临的问题是<li></li>标签颜色没有动态改变。 But i could see 'active item' classes are applying properly when sliding from one image to another in DOM.但是我可以看到'active item'类在 DOM 中从一个图像滑动到另一个图像时正确应用。

Here, what i'm trying to achieve is, i don't want show carousel indicator for single image item only .在这里,我想要实现的是,我不想只为单个图像项目显示轮播指示器 As you can see, i'm rendering image dynamically.如您所见,我正在动态渲染图像。 Everything is working fine except active class color change.除了活动类颜色更改外,一切正常。

Please point my mistake where i'm doing wrong.请指出我做错的地方。

<div id="myCarousel" class="carousel" data-ride="carousel">
    <ol class="carousel-indicators" id="sliderDots"
        *ngIf="respDataList  &&  respDataList.length > 1">
        <ng-container >
            <li data-target="#myCarousel"
                *ngFor="let li of respDataList; let i = index" [attr.data-slide-to]="i"
                class="{{ (i == 0) ? 'active' : '' }}"></li>
        </ng-container>
    </ol>
    <div class="carousel-inner">
        <div *ngFor="let document of respDataList; let i = index"
            class="{{ (i == 0) ? 'item active' : 'item' }}"
            [innerHTML]="document>
        </div>
    </div>
</div>

This sample demo i've created for some other purpose i want to change it as mentioned above.我为其他目的创建的这个示例演示我想如上所述更改它。

Thanks in advance.提前致谢。

Just add只需添加

<ol class="carousel-indicators" id="adList" *ngIf="mockData.length > 1">

And you have no indicator for less than 2 elements并且您没有少于 2 个元素的指标

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

to make single element only remove // line 16 in app component使单个元素仅删除// app组件中的第 16 行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM