ng2-image-gallery thumbnail undefined

时间:2017-03-24 10:23:31

标签: angular typescript image-gallery

我一直关注ng2-image-gallery documentation,我已经安装了npm,将相关字段添加到我的app.module等。

component.html内,我有这个:

<h2>Image gallery</h2>
<ng2-image-gallery [images]="images" [asThumbnail]="'thumbnail'"></ng2-image-gallery> 

component.ts内,我有这个:

export interface ImageInterface {
    thumbnail?: any; //image src for the thumbnail
    image?: any; //image src for the image 
    text?: string; //optional text to show for the image
    [propName: string]: any;
}

@Component({
  selector: 'app-section',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: []
})

export class AppComponent {

public images: ImageInterface[] = [];

constructor() {

    var t: ImageInterface;

    t.thumbnail = null;
    t.text = null;
    t.image = null;

    t.thumbnail = 'http://media.istockphoto.com/photos/tree-picture-id543052538';
    t.text = 'cool text';
    t.image = 'http://media.istockphoto.com/photos/tree-picture-id543052538';

    this.images.push(t);


}
}

当我运行这个时,我得到TypeError: Cannot set property 'thumbnail' of undefined我对Angular2来说相对较新,所以如果有人可以建议我需要做些什么来启动并运行它,我将非常感激。

0 个答案:

没有答案