Angular: Cannot read property 'insertNode' of undefined at TransitionAnimationEngine

Viewed 742

I have created my own directive, that hides content if user is not logged: *onlyUser. When I try to use it in component that utilises ng/animation I sometimes get an error:

Cannot read property 'insertNode' of undefined at TransitionAnimationEngine

Directive looks like this:

export class OnlyUserDirective {
  constructor(private _templateRef: TemplateRef<any>,
              private _viewContainer: ViewContainerRef,
              private _userContextService: UserContextService) {
    this._userContextService.isLogged$().subscribe(x => {
      if (x === true) {
        this._viewContainer.createEmbeddedView(this._templateRef);
      } else {
        this._viewContainer.clear();
      }
    });
  }
}

And when I try to use it within a component with @Component({ animations: [...] }) I sometimes get the error from this question's beginning. Is this expected behavior, or an angular bug?

1 Answers
Related