1- import {
2- ChangeDetectionStrategy ,
3- Component ,
4- ElementRef ,
5- HostBinding ,
6- inject ,
7- input
8- } from '@angular/core' ;
9- import { DomSanitizer , SafeStyle } from '@angular/platform-browser' ;
10- import { pathToCssUrl } from 'utils/string-utils' ;
1+ import { NgOptimizedImage } from '@angular/common' ;
2+ import { ChangeDetectionStrategy , Component , ElementRef , inject , input } from '@angular/core' ;
113
124@Component ( {
135 selector : 'code-card' ,
6+ imports : [ NgOptimizedImage ] ,
147 templateUrl : './card.component.html' ,
158 styleUrl : './card.component.scss' ,
16- changeDetection : ChangeDetectionStrategy . OnPush
9+ changeDetection : ChangeDetectionStrategy . OnPush ,
10+ host : {
11+ '[class.hoverable]' : 'isHoverOn()'
12+ }
1713} )
1814export class CardComponent {
19- /**
20- * The CSS background image URL.
21- */
22- @HostBinding ( 'style.background-image' ) protected get backgroundImage ( ) : SafeStyle {
23- return this . sanitizer . bypassSecurityTrustStyle ( pathToCssUrl ( this . bgImg ( ) ) ) ;
24- }
25-
26- /**
27- * The CSS class that enables this to be hoverable.
28- */
29- @HostBinding ( 'class.hoverable' ) get hoverable ( ) : boolean {
30- return this . isHoverOn ( ) ;
31- }
32-
33- public elementRef = inject ( ElementRef ) ;
15+ elementRef = inject ( ElementRef ) ;
3416
3517 /**
3618 * URL of the image to use.
@@ -45,9 +27,4 @@ export class CardComponent {
4527 * false makes the card have no hover effects.
4628 */
4729 public isHoverOn = input ( true ) ;
48-
49- /**
50- * Sanitizes inputs for Angular.
51- */
52- private sanitizer = inject ( DomSanitizer ) ;
5330}
0 commit comments