Skip to content

Instantly share code, notes, and snippets.

View realtomaszkula's full-sized avatar

Tomasz Kula realtomaszkula

View GitHub Profile
export interface Theme {
primary: string;
accent: string;
}
interface Theme {
primary: string;
accent: string;
}
@Component({
selector: 'app-root',
template: `<app-card></app-card>`,
})
export class AppComponent {
@Component({
selector: 'app-root',
template: `
<app-card [style]="style"></app-card>
`,
})
export class AppComponent {
get style() {
return this.sanitizer.bypassSecurityTrustStyle(
`--primary: lightblue; --accent: crimson`
@Component({
selector: 'app-root',
template: `
<app-card></app-card>
`,
styles: [`
app-card {
--primary: lightblue;
--accent: crimson;
}
@Component({
selector: 'app-root',
template: `
<app-card style="--primary: lightblue; --accent: crimson"></app-card>
`,
})
export class AppComponent {}
@Component({
selector: 'app-card',
template: `
<header></header>
<main>
<section class="top"></section>
<button class="fab">+</button>
<section class="bottom"></section>
</main>
`,
@Component({
selector: 'app-card',
template: `
<header></header>
<main>
<section class="top"></section>
<button class="fab">+</button>
<section class="bottom"></section>
</main>
`,
@Directive({
selector: 'img[appLazyLoad]'
})
export class LazyLoadDirective implements AfterViewInit {
// ...
constructor(private el: ElementRef) {}
private lazyLoadImage() {
const obs = new IntersectionObserver(entries => {
entries.forEach(({ isIntersecting }) => {
@Directive({
selector: 'img[appLazyLoad]'
})
export class LazyLoadDirective implements AfterViewInit {
@HostBinding('attr.src') srcAttr = null;
@Input() src: string;
ngAfterViewInit() {
this.canLazyLoad() ? this.lazyLoadImage() : this.loadImage();
}
@Directive({
selector: 'img[appLazyLoad]'
})
export class LazyLoadDirective implements AfterViewInit {
@HostBinding('attr.src') srcAttr = null;
@Input() src: string;
private loadImage() {
this.srcAttr = this.src;
}