0

[更新] 我在这里使用 angular 2 carousel:

https://embed.plnkr.co/ScE0uqfd0ZvL6T9j1XjL/

我想添加过渡效果。

在轮播示例 ts 中,我添加了属性

<carousel [interval]="NextPhotoInterval" [noWrap]="noLoopSlides" [noTransition]="noTrans">

我在 carousel-example.ts 中声明的 noTrans 属性为 private noTrans:boolean = false;

noTransition 在轮播组件内

 @Input() public noTransition:boolean;

(默认情况下 noTrans 为 false ,文档应启用转换)。

这没有做任何事情,我看不到任何过渡。有谁知道我错在哪里?

谢谢!

最后,我使用引导程序实现了我的通用轮播,所以我将发布我是如何做到的,以便在有人想使用它时提供帮助:

组件.html:

   <div id="carousel-generic" class="carousel slide" data-ride="carousel" *ngIf="newsData">
            <ol class="carousel-indicators" [hidden]="newsData.length <=1">
                <li data-target="#carousel-generic" *ngFor="let news of newsData; let i= index" attr.data-slide-to="{{i}}" [ngClass]="{active: isActive(news)}"></li>
            </ol>
            <div class="carousel-inner news-loading" role="listbox">
                <div *ngFor="let news of newsData;" class="item" [ngClass]="{active: isActive(news)}">
                    <h4 class="center">{{news.Title}}</h4>
                    <img class="img-responsive" [src]="news.ImageUrl">
                    <div class="news">
                        <p><a target="_blank" href="{{news?.DetailsUrl}}">{{news.Text}}</a></p>
                    </div>
                </div>
                <a class="left carousel-control" href="#carousel-generic" role="button" data-slide="prev" [hidden]="!newsData.length">
                    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="right carousel-control" href="#carousel-generic" role="button" data-slide="next" [hidden]="!newsData.length">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>
        </div>

组件.ts:

@Component({
    selector: 'my-component',
    templateUrl: 'app/components/component.html'
})

export class NewsComponent implements OnInit{
   private newsData: NewsDataModel[];

    constructor(private _service: MyService) {}

    private isActive(news:any){
       return news === this._service.newsData[0]; 
    }

   ngOnInit() {
    this.newsData = this._service.newsData;
  } 
}

*我确实在我的服务中订阅()

4

0 回答 0