Skip to content

Strange errors with HostBinding to observables (Can't bind to '$.class.xxx') #21

Answered by waterplea
loxy asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately for now it's not possible without hacks. You can remove @HostBinding and change your code to this:

@Component({
  selector: 'app-layout',
  templateUrl: './layout.component.html',
  styleUrls: ['./layout.component.scss'],
})
export class LayoutComponent {
  @HostListener('$.class.collapsed')
  readonly collapsed = asCallable(this.ui.sideNav);

  constructor(
    {nativeElement}: ElementRef,
    private ui: UiService,
  ) {
    nativeElement['$.class.collapsed'] = this.ui.sideNav;
  }
}

Also note asCallable utility function, it is there just to trick @HostListener into believing it's a callback.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@loxy
Comment options

@waterplea
Comment options

@loxy
Comment options

Answer selected by loxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants