Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active November 4, 2019 12:22
Show Gist options
  • Save armanozak/0c7f0d5ad4dd3a825a96c26090a6f028 to your computer and use it in GitHub Desktop.
Save armanozak/0c7f0d5ad4dd3a825a96c26090a6f028 to your computer and use it in GitHub Desktop.
Adaptive Components - Dumb Card Image Component #blog
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
@Component({
selector: 'app-card-image',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<img [alt]="alt" [src]="src" [ngClass]="classes" (load)="ready = true" />
<span *ngIf="ready && attribution">
Image by <a [href]="attribution.href">{{ attribution.text }}</a>
</span>
`,
})
export class CardImageComponent {
@Input() alt = '';
@Input() attribution = {
href: 'https://unsplash.com',
text: 'Unsplash',
};
@Input() placement: 'top' | 'side' = 'side';
@Input() src = 'https://picsum.photos/200';
ready = false;
get classes(): string {
return 'card-img-' + this.placement;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment