Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active November 10, 2019 09:56
Show Gist options
  • Save armanozak/08078227d9c293a21e8a14055f704731 to your computer and use it in GitHub Desktop.
Save armanozak/08078227d9c293a21e8a14055f704731 to your computer and use it in GitHub Desktop.
Adaptive Components - Using Properties on Parent Component in Angular #blog
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AbstractCard } from './abstract-card';
import { CardHorizontalComponent } from './card-horizontal.component';
@Component({
selector: 'app-card-button',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<button class="btn" [ngClass]="classes" (click)="parent.action()">
<ng-content></ng-content>
</button>
`,
})
export class CardButtonComponent {
private horizontal = this.parent instanceof CardHorizontalComponent;
get classes(): string {
return this.horizontal
? `btn-link text-${this.parent.color} text-left p-0`
: `btn-${this.parent.color} btn-block mt-4`;
}
constructor(public parent: AbstractCard) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment