简体   繁体   中英

Owl Carousel is not working in Angular 4

I am working on angular 4 and I want to implement owl carousel in my application. I imported owl carousel in the application refer by this link https://www.npmjs.com/package/ng2-owl-carousel .

But images is not coming. I am sharing in my code:

home.component.ts

import { Component } from '@angular/core';
import {Http} from '@angular/http';
import {OwlCarousel} from 'ng2-owl-carousel';
import { ViewChild } from '@angular/core'
declare var $:any;
@Component({
    moduleId:module.id,
    templateUrl:'home.component.html'
})

export class HomeComponent{
    public pageTitle:string ='Home';
    @ViewChild('owlElement') owlElement: OwlCarousel       

      fun() {
        this.owlElement.next([200])
        //duration 200ms
      }
      object = {          
        link: "http://lorempixel.com/100/100"
      }

}

home.component.html

<owl-carousel
[options]="{items: 3, dots: false, navigation: false}"

[items]="images"

[carouselClasses]="['owl-theme', 'row', 'sliding']">
<div class="item" *ngFor="let image of images;let i = index">
    <div class="thumbnail-image" [ng-style]="{'background-image':'url(/assets/img/images.jpg)'}"></div>
</div>
</owl-carousel>

app.module.ts

imports: [
    BrowserModule,
    HttpModule,
    FormsModule,
    OwlModule
]

在此处输入图片说明 Only next or prev is coming but Image is not coming. I am new in angular 4. So I am not able to solve this problem. I have seen links But Still I am not able to solve.

angularjs ng-style: background-image isn't working
Angular 2 - background image into a html file using ngStyle

i don't see any images inside your loop, add img inside your ngFor:

       <img src="{{image}}" style="" />

and use

      [ngStyle] and not [ng-style]

have you included css and js as given in here

"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/owl.carousel/dist/owl.carousel.js"

]

"styles": [ "../node_modules/owl.carousel/dist/assets/owl.carousel.css", "../node_modules/owl.carousel/dist/assets/owl.theme.default.css" ]

2]don't use background images use like below `

`

  1. may be image url path may wrong [ng-style]="{'background-image':'url(/assets/img/images.jpg)'}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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