adding an angular animation to a host element

Oliver Renner picture Oliver Renner · Aug 16, 2016 · Viewed 16.4k times · Source

i added an animation to the host via

@Component({
   ....,
   animations: [
      trigger('slideIn', [
          ...
      ])
   ],
   host: {
      '[@animation]': 'condition'
   }
}

which worked well, on compilation i was told this is deprecated and i should use @HostBinding ...

@HostBinding('[@animation]') get slideIn() {
   return condition;
}

which throws me an error

Can't bind to '[@animation' since it isn't a known property of 'my-component-selector'.

but i cannot add an animation into my module.. what can i do ?

Answer

Günter Zöchbauer picture Günter Zöchbauer · Aug 16, 2016

The square brackets are not necessary with @HostBinding()

@HostBinding('@slideIn') get slideIn() {

There are two decorators @HostBinding() and @HostListener() therefore the distinction between () and [] isn't necessary, while it is when host: [...] is used.