I have an element in an ng2 component that I want to manipulate directly. I don't need or want its properties to be handled by the framework because its properties will be updated on a second-by-second basis and I don't want it affecting the lifecycle. In my example (not the actual use case) I will use a timer that increments per second.
HTML-
<div class="timer"></div>
<div>Elapsed</div>
Component-
@Component({
selector: 'timer',
templateUrl: 'timer.html',
})
export class TimerComponent {
private time = 0;
// How do I get .timer ?
constructor(private $element: ElementRef) {}
onNgInit() {
setInterval(this.incrementTimer.bind(this), 1000);
}
private incrementTimer() {
this.time++;
this.$element.nativeElement.innerHTML = this.time;
}
}
I have a number of options to get the timer element, but I'm wondering if there is an easy way (an angular way) to label the element so that angular will understand/include it in the injector. I'd prefer not to search the DOM for this element, and I prefer not to tap the lifecycle every time I want to update.