2016-08-16 37 views
7

我通過添加角動畫主機元素

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

它運作良好,在編譯有人告訴我不贊成這種方式,我應該使用@HostBinding添加動畫到主機...

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

這引發了我一個錯誤

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

,但我不能添加動畫到我的模塊..我能做些什麼?

回答

13

方括號是沒有必要與@HostBinding()

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

有兩個裝飾@HostBinding()@HostListener()()因此和[]之間的區別不是必須的,而它是當使用host: [...]