什么是角度合成属性?

zgu*_*gue 6 typescript angular angular-animations

最近,在开发动画组件时,我遇到了这个术语synthetic property.

<bmx-panel [@sidebarState]="state">

  <i bmxPanelHeader (click)="toggle($event)"
     class="fa fa-angle-double-right fa-lg"></i>
  ...    
</bmx-panel>
Run Code Online (Sandbox Code Playgroud)

在我的情况下,[@sidebarState]="state"当函数state更改属性时,合成属性会触发组件的展开/折叠动画toggle.

方法的第一个参数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";  
  }
}
Run Code Online (Sandbox Code Playgroud)

谷歌搜索没有提供有关合成属性的大量信息.角度文档中也没有提到任何内容.有没有人对这个概念有更深入的了解?

Sea*_*den 2

它是合成的,因为它看起来像一种 Angular 属性,但其行为与常识不同。该术语只是描述性的。