Angular 角度@组件装饰器内的动态变量

Angular 角度@组件装饰器内的动态变量,angular,ecmascript-6,angular2-components,angular2-animation,angular2-decorators,Angular,Ecmascript 6,Angular2 Components,Angular2 Animation,Angular2 Decorators,我想将动态变量传递给angular@Component类装饰器 从示例中可以看到,有一个项目列表。 我希望每个项目最初都以不同的角度旋转-${DYNAMIC\u degree\u VAR} 如果我直接将transform设置为random value:旋转(${Math.floor(Math.random()*15+1)}度)-每个项目都将具有相同的随机值 任何提示,谢谢 @Component({ selector: 'my-list', templateUrl: 'my-lis

我想将动态变量传递给angular
@Component
类装饰器

从示例中可以看到,有一个项目列表。 我希望每个项目最初都以不同的角度旋转-
${DYNAMIC\u degree\u VAR}

如果我直接将transform设置为random value:
旋转(${Math.floor(Math.random()*15+1)}度)
-每个项目都将具有相同的随机值

任何提示,谢谢

@Component({
    selector: 'my-list',
    templateUrl: 'my-list.component.html',
    styleUrls: ['my-list.component.css']
})
export class MyListComponent implements OnInit {
  items: ItemModel[] = [];
}


@Component({
    selector: 'my-item',
    templateUrl: 'my-item.component.html',
    styleUrls: ['my-item.component.css'],
    animations: [
        trigger('itemState', [
            state('inactive', style({
                transform: `rotate(${DYNAMIC_DEGREE_VAR}deg)`
            })),
            state('active', style({
                transform: `rotate(0deg)`
            })),
            transition('inactive => active', animate('100ms ease-in')),
            transition('active => inactive', animate('100ms ease-out'))
        ])
    ]
})
export class MyItemComponent implements OnInit {

   item: ItemModel;

   state: string = 'inactive';
}

// ---------------------------------------------------------

// my-item.component.html
<div [@itemState]="state"></div>

// my-list.component.html
<my-item [item]="item" *ngFor="let items of item"></my-item>
@组件({
选择器:“我的列表”,
templateUrl:'my list.component.html',
样式URL:['my-list.component.css']
})
导出类MyListComponent实现OnInit{
项目:ItemModel[]=[];
}
@组成部分({
选择器:“我的项目”,
templateUrl:'my item.component.html',
样式URL:['my-item.component.css'],
动画:[
触发器('itemState'[
状态('inactive',样式({
变换:`旋转(${DYNAMIC_DEGREE_VAR}deg)`
})),
状态('active',样式({
变换:`旋转(0度)`
})),
过渡('inactive=>active',动画('100ms慢进'),
过渡('active=>inactive',动画('100ms缓解'))
])
]
})
导出类MyItemComponent实现OnInit{
项目:项目模型;
状态:字符串='inactive';
}
// ---------------------------------------------------------
//my-item.component.html
//my-list.component.html

您是否尝试过使用此
转换:旋转(${this.DYNAMIC_DEGREE_VAR}deg)
并在class@PardeepJain对遗憾的是,decorator无法访问类属性。哦,不知道对不起:(我可以在我的类和decorator之外使用const,但正如alex提到的,它不能处理类属性。