1

In Angular 2 project, I am trying to resize a DOM element that I retrieve by id. I set the size as listed below and I don't observe any change. What step am I missing?

        document.getElementById('my_grid').setAttribute("style","height:600px");
reza
  • 5,972
  • 15
  • 84
  • 126

3 Answers3

2

Don't use like this. You can use angular 2 feature.

  1. You can use [style.height.px]="modelvalue"
  2. Second way, you can use <div #mydiv> in html and use @ViewChild in component
Example
@ViewChild mydiv;

resizeDiv() {
    this.mydiv.nativeElement...
}
Kishan Mundha
  • 2,989
  • 18
  • 26
0

You need to set the height to a <div> element. Your browser won't interpret the height attribute on an Angular directive.

Furthermore, the prefered way to access elements in your DOM is via the @ViewChild decorator. See accessing native elements in angular2

Community
  • 1
  • 1
Jan B.
  • 6,030
  • 5
  • 32
  • 53
0

In angular 2 whenever possible never use core javascript or jquery code to manipulate dom element. Try first with do angular 2 features.

We can use [style.height.px]="height" and whenever you want to change div height change height value from component

nisha
  • 1
  • 2