Image has built-in performance and accessibility optimizations that allow users to easily display responsive images.
Image builds on Angular's NgOptimizedImage to provide responsive images with stable layouts out of the box. It helps to avoid common image-related performance and accessibility issues by:
width and height attributesalt textTo use image in a standalone component, import DAFF_IMAGE_COMPONENTS directly into your custom component:
import { Component } from '@angular/core';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_IMAGE_COMPONENTS,
],
})
export class CustomComponent {}
To use image in a module, import DaffImageModule into your custom module:
import { NgModule } from '@angular/core';
import { DaffImageModule } from '@daffodil/design/image';
import { CustomComponent } from './custom.component';
@NgModule({
declarations: [
CustomComponent,
],
exports: [
CustomComponent,
],
imports: [
DaffImageModule,
],
})
export class CustomComponentModule { }
Warning
This method is deprecated. It's recommended to update all custom components to standalone.
All four of the following attributes are required and will throw an error if missing:
| Attribute | Description |
|---|---|
src |
The image source URL |
alt |
Alternative text describing the image |
width |
The intrinsic width of the image in pixels |
height |
The intrinsic height of the image in pixels |
Use the skeleton property to display a placeholder skeleton screen that helps reduce load-time frustration.
Use the priority property to mark an image as a priority for loading. Priority images are loaded eagerly and not lazy-loaded.
Provide concise, meaningful descriptions that convey the content and purpose of the image by using the alt attribute. An error will be thrown if alt is missing.