Answer the question
In order to leave comments, you need to log in
Get keys of objects in an array?
<picture *ngIf="image" class="al-image-container">
<source
*ngFor="let imageFormat of image.imageTypes"
[srcset]="imageFormat.imageSizes.source"
[type]="imageFormat.type"
[media]="imageFormat.imageSizes.mediaQuerySize"
>
<img
class="al-image"
[src]="defaultImageSrc"
[alt]="(image.alt || '') | translate"
>
</picture>
const imageConfigObject: AlImage = {
imageTypes: [
{
imageSizes: [
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.DESKTOP,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.LAPTOP_L,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.LAPTOP,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.TABLET,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.MOBILE,
default: false,
},
],
type: ImageType.WEBP,
default: false,
},
{
imageSizes: [
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.DESKTOP,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.LAPTOP_L,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.LAPTOP,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.TABLET,
default: false,
},
{
source: `${imagesFolderPath}/webp/${imageName}.webp`,
mediaQuerySize: MediaQuerySize.MOBILE,
default: false,
},
],
type: imageExt === 'png' ? ImageType.PNG : ImageType.JPEG,
default: true,
},
],
alt,
};
export enum ImageType {
WEBP = 'image/webp',
JPEG = 'image/jpeg',
PNG = 'image/png',
}
export enum MediaQuerySize {
DESKTOP = '(max-width: 1920px)',
LAPTOP_L = '(max-width: 1440px)',
LAPTOP = '(max-width: 1024px)',
TABLET = '(max-width: 768px)',
MOBILE = '(max-width: 425px)',
}
export interface AlImageType {
type: ImageType;
default?: boolean;
imageSizes: AlImageSize[];
}
export interface AlImageSize {
source: string;
mediaQuerySize: MediaQuerySize;
default?: boolean;
}
export interface AlImage {
imageTypes: AlImageType[];
alt?: string;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question