迭代Angular4

时间:2017-08-09 12:24:05

标签: javascript css angular swiper

我目前正在使用Swiper(https://www.npmjs.com/package/angular2-useful-swiper)来创建图片库。

是否可以通过迭代对象数组并使用ngClass来动态更改div的类?我不确定是否支持插值。

我不断收到的错误说明"标识符'样式'没有定义。 '阵列'不包含这样的会员。'但是为什么ngStyle,h4和p能够抓住元素并迭代它,如果是这样的呢?

slider.component.html

<div class="swiper-container">
  <swiper class="swiper" [config]="config">
    <div class="swiper-wrapper">
        <div class="swiper-slide" *ngFor="let image of images">
            <div class="swiper-slide--container">
              <div class="symptom-slide-img"
              [ngClass]="images.style" [ngStyle]="{'background-image': 'url(' + image.src + ')'}"></div>
              <div class="caption">
                  <h4>{{ image.title }}</h4>
                  <p>{{ image.caption}}</p>
              </div>
            </div>

      </div>
    </div>
    <div class="swiper-button-next"></div>
    <div class="swiper-button-prev"></div>
  </swiper>
</div>

slider.component.ts

import { Component, OnInit } from '@angular/core';
import { NgClass } from '@angular/common';

@Component({
  selector: 'app-symptoms-slider',
  templateUrl: './symptoms-slider.component.html',
  styleUrls: ['./symptoms-slider.component.scss']
})
export class SymptomsSliderComponent implements OnInit {

images = [  {
                'src': './path/image.png',
                'title': 'Title',
                'style': 'hvr-pulse-grow',
                'caption':
                'Caption'
            },
            {
                'src': './path/image.png',
                'title': 'Title',
                'style': 'hvr-buzz',
                'caption':
                'Caption'
            },
            {
                'src': './path/image.png',
                'title': 'Title',
                'style': 'hvr-wobble-vertical',
                'caption':
                'Caption'
            },
            {
                'src': './path/image.png',
                'title': 'Title',
                'style': 'hvr-wobble-vertical',
                'caption':
                'Caption'
            },
        ];

  constructor() { }

  ngOnInit() {
  }
}

1 个答案:

答案 0 :(得分:1)

错字

[ngClass]="images.[ngClass]="image.(删除不必要的&#39;)