I am testing a simple animation in / fade out on a button using Angular 4 animations. The problem I am facing is that since I use booleans, nothing starts. From the dev tools, it looks like a class is .ng-animating
added to an element, but nothing changes.
This is the sample code that I have:
@Component({
selector: 'fade-btn-test',
styles: [
require('./fade-btn-test.component.scss')
],
template: `
<button [@test]="isActive" (click)="isActive = !isActive">My Button</button>
`,
animations: [
trigger('test', [
state('true', style({ opacity: 0 })),
state('false', style({ opacity: 1 })),
transition('0 <=> 1', animate(500))
])
]
})
export class FadeBtnTestComponent {
isActive: boolean = false;
}
I know that the above code was used to work with Angular 2, however in this case it does not work. The only solution I found was to work with string
instead boolean
.
@Component({
selector: 'fade-btn-test',
styles: [
require('./fade-btn-test.component.scss')
],
template: `
<button [@test]="isActive.toString()" (click)="isActive = !isActive">My Button</button>
`,
animations: [
trigger('test', [
state('true', style({ opacity: 0 })),
state('false', style({ opacity: 1 })),
transition('true <=> false', animate(500))
])
]
})
export class FadeBtnTestComponent {
isActive: boolean = false;
}
From the above code, you will notice that the animation trigger @test
reads the string ( isActive.toString()
), and the function transition
has true <=> false
instead 0 <=> 1
.
, , - Animation. - - Angular 4?