我一直关注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来说相对较新,所以如果有人可以建议我需要做些什么来启动并运行它,我将非常感激。