Я новичок в ng-bootstrap и тестирую ngb-carousel.Если я просто скопирую и вставлю пример со страницы, он будет работать отлично, но я не смогу заставить его работать с тем кодом, который я пишу.Я не вижу, чего мне не хватает.
Вот код mi
Это carousel.component.html
<ngb-carousel *ngIf="contents" [showNavigationArrows]="showNavigationArrows" [showNavigationIndicators]="showNavigationIndicators">
<ng-template ngbSlide *ngFor="let i of contents">
<img [src]="i.imgRoute" alt="{{i.imgAlt}}">
<div class="carousel-caption">
<h3>No mouse navigation</h3>
<p>This carousel hides navigation arrows and indicators.</p>
</div>
</ng-template>
<div class="btn-group" role="group" aria-label="Carousel toggle controls">
<button type="button" (click)="showNavigationArrows = !showNavigationArrows" class="btn btn-outline-dark btn-sm">Toggle navigation arrows</button>
<button type="button" (click)="showNavigationIndicators = !showNavigationIndicators" class="btn btn-outline-dark btn-sm">Toggle navigation indicators</button>
</div>
А это мой carousel.component.ts
import { Component, OnInit } from '@angular/core';
import { ContentService } from '../content.service';
import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-carousel',
templateUrl: './carousel.component.html',
styleUrls: ['./carousel.component.css'],
providers: [NgbCarouselConfig]
})
export class CarouselComponent implements OnInit {
contents = [];
selectedIndex: number;
transform: number;
showNavigationArrows = false;
showNavigationIndicators = false;
test: string;
constructor(config: NgbCarouselConfig, private _contentService: ContentService) {
config.showNavigationArrows = true;
config.showNavigationIndicators = true;
this.selectedIndex = 0;
this.transform = 100;
this.test = 'https://picsum.photos/900/500/?image=939';
}
ngOnInit() {
this._contentService.getContent()
.subscribe(content => this.contents = content);
}
}