Currently, I am facing an issue with an animation that is supposed to expand the height on hover. The problem arises because the height of the label is auto-generated and does not animate properly with just the :hover selector. Below is a snippet from my TypeScript @Component file where I have defined the animation:
@Component({
selector: 'app-create',
templateUrl: './create.component.html',
styleUrls: ['./create.component.css'],
animations: [
trigger('buttonState', [
state('inactive', style({
height: '100%'
})),
state('active', style({
height: this.buttonHeight
})),
transition('inactive => active', animate('1.5s ease-in')),
transition('active => inactive', animate('1.5s ease-out'))
])
]
})
The current issue I am encountering is that when trying to access this.buttonHeight, I receive an error stating "Cannot read property 'buttonHeight' of undefined". This leads me to believe that 'this' refers to something other than the class in the @Component or it may not be defined yet. How can I resolve this?
This is how I am calculating the height:
@ViewChild('button') button : ElementRef;
buttonHeight : number;
ngOnInit() {
this.buttonHeight = this.button.nativeElement.offsetHeight
}
In the HTML template:
<label [@buttonState]="state" (mouseover)="toggleState()" (mouseout)="toggleState()">