作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 Angular 2 编写轮播/ slider 代码。我的想法是,我有一组图像,
export class AppComponent {
title = 'app works!';
images: Array<any> = [
{
image: "1.jpg"
},
{
image: "2.jpg"
},
{
image: "3.jpg"
},
{
image: "4.jpg"
},
{
image: "5.jpg"
},
{
image: "6.jpg"
}
];
}
我想遍历图像数组并将 div 的背景图像替换为 {{images.image}}
的当前值。
我设置了一个计数器,
public subscription: any;
public time: any;
ngOnInit() {
let timer = TimerObservable.create(1000,5000);
this.subscription = timer.subscribe(t=>{
this.time = t;
})
}
目标div
看起来像
<div class="slider__home" style="background: url({{image}})">
</div>
我如何实现这一点?我不想使用 bootstrap 或 jQuery,而只是普通的 Angular2,感谢您的帮助。
最佳答案
像这样:
<div class="slider__home" [style.background]="'url('+ image +')'">
</div>
关于angular - 从头开始使用 Angular 2 的旋转木马/ slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39756289/
我需要用这样的数据构建一个表: ┌────────┬───────────┬────────┐ │ ID │ Name │ Age │ ├────
我是一名优秀的程序员,十分优秀!