Last active
December 29, 2016 21:05
-
-
Save jsayol/92a0dd435e35d92cda6fa585dd5a9a4d to your computer and use it in GitHub Desktop.
This file contains 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: 'blink', | |
template: `<ng-content></ng-content>` | |
}) | |
export class BlinkComponent implements OnInit { | |
private element: Element; | |
private blinker$: Observable<string>; | |
constructor(private renderer: Renderer, elementRef: ElementRef) { | |
this.element = elementRef.nativeElement; | |
const show$ = Observable.timer(0, 1000); | |
const hide$ = Observable.timer(750, 1000); | |
this.blinker$ = Observable.merge( | |
show$.mapTo('visible'), | |
hide$.mapTo('hidden') | |
); | |
} | |
private set visibility(value: string) { | |
this.renderer.setElementStyle(this.element, 'visibility', value); | |
} | |
ngOnInit() { | |
this.blinker$.subscribe((newVisiblity: string) => this.visibility = newVisiblity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment