我想知道使用@HostBinding
和組件的host
屬性之間是否存在巨大差異(如果存在,它是什麼?)?Angular2:@HostBinding或主機:{}?
我一直在問自己,而我使用的動畫,因爲我是在這些情況下(這看起來相當接近)這個問題:
@Component({
selector: 'mycomponent',
animations: [
trigger('myTransition', [
state('inactive', style({
backgroundColor: '#eee',
transform: 'scale(1)'
})),
state('active', style({
backgroundColor: '#cfd8dc',
transform: 'scale(1.1)'
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
])],
host: {
'[@myTransition]': '',
},
})
OR
@Component({
selector: 'mycomponent',
animations: [
trigger('myTransition', [
state('inactive', style({
backgroundColor: '#eee',
transform: 'scale(1)'
})),
state('active', style({
backgroundColor: '#cfd8dc',
transform: 'scale(1.1)'
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
])],
})
export class MyComponent {
@HostBinding('@myTransition') get myTransition() {
return '';
}
}
我當時以爲是我的可能是主機綁定的新方式。
在此先感謝您的建議和意見;)
好吧,所以它只是另一種使用主機綁定的方式,就像輸入:[]和@Input? – nicolasrigaudiere
是的,裝飾器可用的所有東西都可以在'host'中找到,反之亦然。 –