尝试做旋转木马并把图片作为背景,希望有人可以帮助我,抱歉我的英文破碎:) 这里我键入的代码: 第一个角度:
import { Component, OnInit } from '@angular/core';
import { NgStyle } from '@angular/common';
import { NgFor } from '@angular/common';
@Component({
selector: 'app-slider',
templateUrl: './slider.component.html',
styleUrls: ['./slider.component.css']
})
export class SliderComponent implements OnInit {
constructor() { }
images = [];
ngOnInit() {
this.images = [
{"id":1, "url":"assets/img/header.jpeg"},
{"id":2, "url":"assets/img/velo2.jpeg"},
{"id":3, "url":"assets/img/velo3.jpeg"},
]
}
}
和我的HTML代码:
<carousel >
<slide *ngFor = "let image of images" >
<div [ngStyle]="{'background-image': url(' + image.url + ')}"></div>
</slide>
</carousel>
这是我的错误:
ERROR TypeError: _co.url is not a function
at Object.eval [as updateDirectives] (ng:///AppModule/SliderComponent.ngfactory.js:17)
at Object.debugUpdateDirectives [as updateDirectives] (vendor.bundle.js:82907)
at checkAndUpdateView (vendor.bundle.js:82087)
at callViewAction (vendor.bundle.js:82452)
at execEmbeddedViewsAction (vendor.bundle.js:82410)
at checkAndUpdateView (vendor.bundle.js:82088)
at callViewAction (vendor.bundle.js:82452)
at execComponentViewsAction (vendor.bundle.js:82384)
at checkAndUpdateView (vendor.bundle.js:82093)
at callViewAction (vendor.bundle.js:82452)