This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[carousel]' | |
}) | |
export class CarouselDirective implements OnInit, OnDestroy { | |
// ... | |
timerId: number | null = null; | |
@Input('carouselAutoplay') | |
set autoplay(autoplay: 'on' | 'off') { | |
autoplay === 'on' ? this.setAutoplayTimer() : this.clearAutoplayTimer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div *carousel="let image from images; let ctrl = controller"> | |
<img [src]="image"> | |
<button (click)="ctrl.prev()">Previous</button> | |
<button (click)="ctrl.next()">Next</button> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[carousel]' | |
}) | |
export class CarouselDirective implements OnInit { | |
context: CarouselContext | null = null; | |
index = 0; | |
constructor( | |
private tpl: TemplateRef<CarouselContext>, | |
private vcr: ViewContainerRef |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[carousel]' | |
}) | |
export class CarouselDirective implements OnInit { | |
context: CarouselContext | null = null; | |
constructor( | |
private tpl: TemplateRef<CarouselContext>, | |
private vcr: ViewContainerRef | |
) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface CarouselContext { | |
$implicit: string; | |
controller: { | |
next: () => void; | |
prev: () => void; | |
}; | |
} | |
@Directive({ | |
selector: '[carousel]' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scroll$ = fromEvent(window, 'scroll').pipe( | |
throttleTime(10), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-sticky-header', | |
template: `<ng-content></ng-content>`, | |
styles: [ ... ] | |
}) | |
export class StickyHeaderComponent implements AfterViewInit { | |
private isVisible = true; | |
ngAfterViewInit() { | |
const scroll$ = fromEvent(window, 'scroll').pipe( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scroll$ = fromEvent(window, 'scroll').pipe( | |
throttleTime(10), | |
map(() => window.pageYOffset), | |
pairwise(), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger('toggle', [ | |
state( | |
VisibilityState.Hidden, | |
style({ opacity: 0, transform: 'translateY(-100%)' }) | |
), | |
state( | |
VisibilityState.Visible, | |
style({ opacity: 1, transform: 'translateY(0)' }) | |
), | |
transition('* => *', animate('200ms ease-in')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum VisibilityState { | |
Visible = 'visible', | |
Hidden = 'hidden' | |
} | |
@HostBinding('@toggle') | |
get toggle(): VisibilityState { | |
return this.isVisible ? VisibilityState.Visible : VisibilityState.Hidden; | |
} |