Issue
I want to import BS carousel in a Angular component but it doesn't works. BS styles are well imported as I can use BS classes. I read many tutos so I don't see what I'm missing. I see about ng-bootstrap but I prefer a solution without it. I show the relevant code I added in following files.
// angular.json
[...]
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
],
// app.module.ts
[...]
import $ from 'jquery';
import { Carousel } from 'bootstrap';
@NgModule({
declarations: [
AppComponent,
AvisComponent,
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [
AppComponent,
AvisComponent,
]
})
// avis.component.ts
import { Component } from '@angular/core';
import $ from 'jquery';
import { Carousel } from 'bootstrap';
@Component({
selector: 'app-avis',
templateUrl: './avis.component.html',
styleUrls: ['./avis.component.css']
})
export class AvisComponent {
ngOnInit() {
console.log(Carousel); // Log the BS class
console.log($('#myCarousel).carousel()); // Log "carousel is not a function"
}
}
Solution
I tried @Naren Murali solution but no result. I finally tried with ngx-bootstrap but not working too. The trick was for my case was to use BS 4.3.1 instead of BS 5.3.2. Can't explain why.
Answered By - TikTaZ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.