我正在研究角度4,我想在我的应用程序中实现owl carousel。我在应用程序中导入了owl carousel,请参阅此链接https://www.npmjs.com/package/ng2-owl-carousel。
但图像不会出现。 我在我的代码中分享:
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
]
只有下一个或上一个会来,但Image不会来。我是角度4的新手。所以我无法解决这个问题。我看过链接但是我仍然无法解决。
angularjs ng-style: background-image isn't working
Angular 2 - background image into a html file using ngStyle
答案 0 :(得分:0)
我在你的循环中没有看到任何图像,在你的ngFor中加入img:
<img src="{{image}}" style="" />
并使用
[ngStyle] and not [ng-style]
答案 1 :(得分:0)
是否包含了here
中给出的css和js"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]不要使用背景图片
使用如下
`
`