在Angular 中声明ImageObject 格式在哪里?
Where is the to declare the ImageObject format in Angular?
为了创建像这里这样的图像滑块,我必须从某个地方加载图像,但不幸的是我不确定在哪个文件中(也许 component.ts?)我必须声明
imageObject: Array<object> = [{
image: 'assets/img/slider/1.jpg',
thumbImage: 'assets/img/slider/1_min.jpeg',
alt: 'alt of image',
title: 'title of image'
}, {
image: '.../iOe/xHHf4nf8AE75h3j1x64ZmZ//Z==', // Support base64 image
thumbImage: '.../iOe/xHHf4nf8AE75h3j1x64ZmZ//Z==', // Support base64 image
title: 'Image title', //Optional: You can use this key if want to show image with title
alt: 'Image alt' //Optional: You can use this key if want to show image with alt
}
];
还有在哪里(函数应该是什么样子)。我要实现幻灯片的组件名为 Carousel,如下所示:
@Component({
selector: 'carousel',
templateUrl: './carousel.html',
styleUrls: ['./carousel.component.scss', '../profile.scss']
})
export class Carousel implements OnInit {
ngOnInit(): void {
}
我应该在 OnInit 中声明图像对象吗?
非常感谢!
没错。可以在ngOnInit
函数中创建,这样就可以在实例化组件的时候创建对象。
为了使其更简洁,您可以创建一个函数来创建 imageObject
并在 ngOnInit
函数中调用它。
为了创建像这里这样的图像滑块,我必须从某个地方加载图像,但不幸的是我不确定在哪个文件中(也许 component.ts?)我必须声明
imageObject: Array<object> = [{
image: 'assets/img/slider/1.jpg',
thumbImage: 'assets/img/slider/1_min.jpeg',
alt: 'alt of image',
title: 'title of image'
}, {
image: '.../iOe/xHHf4nf8AE75h3j1x64ZmZ//Z==', // Support base64 image
thumbImage: '.../iOe/xHHf4nf8AE75h3j1x64ZmZ//Z==', // Support base64 image
title: 'Image title', //Optional: You can use this key if want to show image with title
alt: 'Image alt' //Optional: You can use this key if want to show image with alt
}
];
还有在哪里(函数应该是什么样子)。我要实现幻灯片的组件名为 Carousel,如下所示:
@Component({
selector: 'carousel',
templateUrl: './carousel.html',
styleUrls: ['./carousel.component.scss', '../profile.scss']
})
export class Carousel implements OnInit {
ngOnInit(): void {
}
我应该在 OnInit 中声明图像对象吗?
非常感谢!
没错。可以在ngOnInit
函数中创建,这样就可以在实例化组件的时候创建对象。
为了使其更简洁,您可以创建一个函数来创建 imageObject
并在 ngOnInit
函数中调用它。