Why ElementRef is not secure to use if so, what we can use instead?
I'm been using this ElementRef to see or watch a specific html tag and then to send as specific width after is initialize, but if this open a security risk I will not use it, and to be honest I don't understand why angular 2 teams allow this kind security flaws in their framework.
What is the secure and best technique to use? My test component below:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-standard',
template: ` <button type="button" #buttonW></button>`,
})
export class standardComponent implements OnInit {
name: string = 'app-standard';
viewWidthButton: any;
@ViewChild( 'buttonW' ) elButtonW: ElementRef;
constructor() {
this.viewWidthButton = this.elButtonW.nativeElement.offsetWidth;
console.log ('button width: ' + this.viewWidthButton);
}
ngOnInit() {
}
}
Angular 2 page reference:
https://angular.io/docs/ts/latest/api/core/index/ElementRef-class.html