refactor(components): ViewChild instead of querying dom

This commit is contained in:
nixa 2016-05-20 20:00:36 +03:00
parent b05f525a7c
commit d1307b8f58
4 changed files with 10 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import {Component, ViewEncapsulation, Input, Output, ElementRef, EventEmitter} from '@angular/core';
import {Component, ViewChild, ViewEncapsulation, Input, Output, ElementRef, EventEmitter} from '@angular/core';
import {Chartist} from './baChartistChart.loader.ts';
@ -18,14 +18,10 @@ export class BaChartistChart {
@Input() baChartistChartClass:string;
@Output() onChartReady = new EventEmitter<any>();
constructor (private _elementRef:ElementRef) {
}
@ViewChild('baChartistChart') private _selector:ElementRef;
ngAfterViewInit() {
let el = this._elementRef.nativeElement.querySelector('.ba-chartist-chart');
let chart = new Chartist[this.baChartistChartType](el, this.baChartistChartData, this.baChartistChartOptions, this.baChartistChartResponsive);
let chart = new Chartist[this.baChartistChartType](this._selector.nativeElement, this.baChartistChartData, this.baChartistChartOptions, this.baChartistChartResponsive);
this.onChartReady.emit(chart);
}
}

View file

@ -1 +1 @@
<div class="ba-chartist-chart {{baChartistChartClass || ''}}"></div>
<div #baChartistChart class="ba-chartist-chart {{baChartistChartClass || ''}}"></div>