I'm learning Angular 6 at the moment and ran into a bit of a problem. I'm using this tutorial: https://www.yearofmoo.com/2017/06/new-wave-of-animation-features.html
When i click the button, the animation triggers as expected, but after the fade out the text pops up back again. Any ideas why it switches back to the original state?
Thanks in advance
app.component.html
<button (click)="toggle()">Toggle Fade</button>
<div [@someCoolAnimation]="bindingVar">hello there</div>
app.component.ts
import { Component } from '@angular/core';
import {trigger, transition, style, animate} from "@angular/animations";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [
trigger('someCoolAnimation', [
transition('* => fadeIn', [
style({ opacity: 0 }),
animate(1000, style({ opacity: 1 }))
]),
transition('* => fadeOut', [
animate(1000, style({ opacity: 0 }))
])
])
]
})
export class AppComponent {
bindingVar = '';
fadeIn() {
this.bindingVar = 'fadeIn';
}
fadeOut() {
this.bindingVar = 'fadeOut';
}
toggle() {
this.bindingVar == 'fadeOut' ? this.fadeIn() : this.fadeOut();
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }