【问题标题】:What is a angular synthetic property?什么是角度合成属性?
【发布时间】: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


    【解决方案1】:

    它是合成的,因为它看起来像一个 Angular 属性,但并不像常识中的一个。该术语只是描述性的。

    【讨论】:

    • 我如何自己创建合成属性?
    • 我不知道 :)
    猜你喜欢
    • 2015-06-18
    • 2010-11-17
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 2012-05-11
    • 2018-03-27
    相关资源
    最近更新 更多