【发布时间】:2017-07-26 16:56:29
【问题描述】:
我想知道使用组件的@HostBinding 和host 属性之间是否存在巨大差异(如果存在,它是什么?)?
我在使用动画时一直在问自己这个问题,因为我在这些情况下(看起来很接近):
@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]': '',
},
})
或
@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 '';
}
}
然后我认为这可能是主机绑定的新方式。
提前感谢您的建议和意见;)
【问题讨论】: