Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active November 8, 2019 08:05
Show Gist options
  • Save armanozak/249f2f8951d1c4f98d7a9c382ca4833b to your computer and use it in GitHub Desktop.
Save armanozak/249f2f8951d1c4f98d7a9c382ca4833b to your computer and use it in GitHub Desktop.
Adaptive Components - Not-So-Dumb Card Image Component #blog
import {
ChangeDetectionStrategy,
Component,
Input,
Optional,
} from '@angular/core';
import { CardVerticalComponent } from './card-vertical.component';
@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() src = 'https://picsum.photos/200';
ready = false;
classes = `card-img-${this.vertical ? "top" : "side"}`;
constructor(@Optional() public vertical: CardVerticalComponent) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment