【发布时间】:2018-05-14 23:22:56
【问题描述】:
最近,在开发动画组件时,我遇到了synthetic property这个术语。
<bmx-panel [@sidebarState]="state">
<i bmxPanelHeader (click)="toggle($event)"
class="fa fa-angle-double-right fa-lg"></i>
...
</bmx-panel>
在我的例子中,当state 属性被toggle 函数更改时,合成属性[@sidebarState]="state" 会触发我的组件的展开/折叠动画。
trigger方法的第一个参数是对应的合成属性名称@sidebarState。
@Component({
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
animations: [
trigger('sidebarState', [
state('expanded', style( { width: '240px' } )),
state('collapsed', style({ width: '40px' })),
transition('expanded => collapsed', animate('350ms ease-in')),
transition('collapsed => expanded', animate('350ms ease-out'))
])
]
})
export class SidebarComponent {
public state = 'expanded';
constructor() {}
toggle(event: any) {
this.state = this.state === "expanded" ? "collapsed" : "expanded";
}
}
谷歌搜索并没有找到太多关于合成属性的信息。角度文档中也没有提到任何内容。有人对这个概念有更多的了解吗?
【问题讨论】:
标签: angular typescript properties angular-animations synthetic