I want to manually perform page transitions in my Angular2 app. So what I have done so far is produced a service that I call from a Component that deals with navigation. When you click on some link, or icon or whatever I call the AnimationService goTo
method. This receives a URL and pushes to an Observable stream / subject. Here is the service so far:
@Injectable()
export class AnimationService {
// should you be a directive?
animationStream: Subject<string> = new Subject<string>();
animationStreamEnd:Subject<string> = new Subject<string>()
constructor() {
// this is to listen for when it is time to navigate to whereever?
this.animationStreamEnd.subscribe(resp => {
// redirect the url / app here
this.router.go(resp);
});
}
goTo(url:string): void {
// so, broadcast down to trigger the css animation...
this.animationStream.next(url);
}
}
the content that I wish to animate has a ngClass
condition in it's HTML template like so [ngClass]="{'animate-left': applyTransitionClass}"
, it looks something like this
<div class="gridClass" [ngClass]="{'animate-left': applyTransitionClass}">
<div class="gridRow">
<route-view></route-view>
</div>
</div>
</div>
and in it's component I have the following code
export class AnotherComponent {
constructor(private animationService: AnimationService) {
public applyTransitionClass: boolean = false;
this.animationService.animationStream.subscribe(resp => {
// resp is a url...
// apply a css class... when that is done we need to broadcast the thing is done...
this.applyTransitionClass = true;
// here I want to listen for when the animation end (it is only 1 second) and tell the animationService to now navigate to wherever
this.animationService.animationStreamEnd.next(resp);
});
}
You can see where I subscribe to the Observable and how I change the value that triggers the css animation. Now within the Component I wish to listen for the end of the css class I have just triggered then let the AnimationService know this has happened by pushing to the animationStreamEnd. However I don't know how to get hold of the animation end event (like "transitionend","oTransitionEnd","transitionend","webkitTransitionEnd"
). I know I could just set a 1 second delay but I want this to use Observables.
I know I haven't explained myself well, I will amend the question should I need to clarify the requirement. Thanks in advance.