Get height of an element in Angular 2

Body

I'm trying to 'slide toggle' an element using Angular 2 Animations.

https://plnkr.co/edit/Dof60vwHp79eiThhj9vW?p=preview

@Component({
  selector: 'app-navigation',
  templateUrl: './navigation.component.html',
  styleUrls: ['./navigation.component.scss'],
  animations: [
      trigger('toggleHeight', [
          state('inactive', style({
            height: '0',
          })),
          state('active', style({
              height: '100%' //this.el.nativeElement.scrollHeight + 'px'
          })),
          transition('inactive => active', animate('300ms ease-in')),
          transition('active => inactive', animate('300ms ease-out'))
      ])
  ]
})

Above code works but I can't exactly see the transition of the height. I know it's not possible to animate a 'height' property with 'auto' value in CSS.

In order to auto generate the height, Is it possible to make it something like,

state('active', style({
   height: this.nativeElement.height + 'px'
})),

?

Thanks.

micronyks

This should work AFAIK.

 height: '*'

Just checked. It works !

You can read more here : https://angular.io/docs/ts/latest/guide/animations.html#!#automatic-property-calculation

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

angular 2 get element id

From Java

ReactJS - Get Height of an element

From Dev

Height not being set on element using Angular 2 directive

From Java

How to get `DOM Element` in Angular 2?

From Java

Angular2 get clicked element id

From Dev

Get the text from an element by clicking in angular 2

From Dev

get element from json array in angular 2

From Dev

Angular 2 - Forms : Get div element value

From Dev

get element from json array in angular 2

From Dev

In NativeScript with Angular2 get element value

From Dev

Angular2 http get first element

From Dev

Angular 2 get element data and remove it

From Dev

How to get the value of the attribute of element in angular 2?

From Dev

Angular directive bind to height of element

From Dev

Angular show element based on height

From Dev

Angular calculated incorrect element height

From Dev

How to get height and width of the video in Angular 2, TypeScript

From Java

Get width/height of SVG element

From Dev

Get height of an element's content

From Dev

AngularJS - Cannot get height of an element

From Dev

Get height of element and use it in css

From Dev

AngularJS: How to get element height

From Dev

Change element height using Angular JS

From Dev

Angular2 proper way to get element/component styles

From Dev

How to get access to an HTML video element in Angular2

From Dev

Angular2 Get reference to element created in ngFor

From Dev

Angular 2 - Access/get the input element inside an *ngFor and ngModel

From Dev

How Get Id of Draggable Element Angular2

From Dev

How to get width of (DOM) Element in Angular2