mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-17 07:50:12 +01:00
refactor(components): ViewChild instead of querying dom
This commit is contained in:
parent
b05f525a7c
commit
d1307b8f58
4 changed files with 10 additions and 15 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import {Component, HostListener, Input, ElementRef} from '@angular/core';
|
||||
import {Component, ViewChild, HostListener, Input, ElementRef} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'ba-back-top',
|
||||
styles: [require('./baBackTop.scss')],
|
||||
template: `
|
||||
<i class="fa fa-angle-up back-top ba-back-top" title="Back to Top"></i>
|
||||
<i #baBackTop class="fa fa-angle-up back-top ba-back-top" title="Back to Top"></i>
|
||||
`
|
||||
})
|
||||
export class BaBackTop {
|
||||
|
|
@ -13,7 +13,9 @@ export class BaBackTop {
|
|||
@Input() showSpeed:number = 500;
|
||||
@Input() moveSpeed:number = 1000;
|
||||
|
||||
constructor (private _elementRef:ElementRef) {
|
||||
@ViewChild('baBackTop') private _selector:ElementRef;
|
||||
|
||||
ngAfterViewInit () {
|
||||
this._onWindowScroll();
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +27,7 @@ export class BaBackTop {
|
|||
|
||||
@HostListener('window:scroll')
|
||||
_onWindowScroll():void {
|
||||
let el = this._elementRef.nativeElement.querySelector('.ba-back-top');
|
||||
let el = this._selector.nativeElement;
|
||||
window.scrollY > this.position ? $(el).fadeIn(this.showSpeed) : $(el).fadeOut(this.showSpeed);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<div class="ba-chartist-chart {{baChartistChartClass || ''}}"></div>
|
||||
<div #baChartistChart class="ba-chartist-chart {{baChartistChartClass || ''}}"></div>
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@ export class BaFullCalendar {
|
|||
|
||||
@ViewChild('baFullCalendar') private _selector:ElementRef;
|
||||
|
||||
constructor () {
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
let calendar = $(this._selector.nativeElement).fullCalendar(this.baFullCalendarConfiguration);
|
||||
this.onCalendarReady.emit(calendar);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue