Reputation: 6358
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");
Upvotes: 1
Views: 445
Reputation: 1
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
Upvotes: 0
Reputation: 3141
Don't use like this. You can use angular 2 feature.
[style.height.px]="modelvalue"
<div #mydiv>
in html and use @ViewChild in component@ViewChild mydiv;
resizeDiv() {
this.mydiv.nativeElement...
}
Upvotes: 2
Reputation: 6448
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
Upvotes: 0