Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created March 19, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremyLikness/3b546c84693e9854b0f7 to your computer and use it in GitHub Desktop.
Save JeremyLikness/3b546c84693e9854b0f7 to your computer and use it in GitHub Desktop.
import {Component, Inject, ElementRef} from 'angular2/core';
import {IConsoleService} from '../services/interfaces';
import {ConsoleService} from '../services/consoleService';
@Component({
selector: 'console',
templateUrl: 'templates/console.html'
})
export class Console {
public lines: string[];
private div: HTMLDivElement;
constructor(
private element: ElementRef,
@Inject(ConsoleService)private consoleService: IConsoleService) {
this.lines = consoleService.lines;
}
ngAfterViewInit() {
var div = <HTMLDivElement>this.element.nativeElement.getElementsByTagName('div')[0];
this.consoleService.logEvent.asObservable().debounceTime(100).subscribe(data => {
div.scrollTop = div.scrollHeight;
});
}
public clear(): void {
this.lines.length = 0;
this.lines.push("Console cleared.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment