我尝试在子模板中添加动画:
<div class="panel panel-default" [@AnimationState]="item.animateState" (click)="toggleAnimateState()">
item.component.ts中的toggleAnimateState()函数:
toggleAnimateState() {
this.item.animateState = this.item.animateState === 'inactive' ? 'active' : 'inactive';
}
在同一个组件中:
import { Component, Input ,Output, EventEmitter, trigger, state, style, transition, animate } from "@angular/core";
import { Item as ItemModel} from "./models/Item";
@Component({
selector: 'item',
templateUrl: 'app/item.component.html' ,
styleUrls : ['app/app.component.css'],
animations : [
trigger('AnimationState',[
state('inactive', style({color:'red'})),
state('active', style({color: 'blue'})),
transition('inactive => active' , animate('1000ms eas-in')),
transition('active => inactive' , animate('5000ms eas-in')),
])
]
})
export class Item {
@Input() item : ItemModel;
}
app.componet.html中的ANd:
<div *ngFor="let item of collection | itemFilter:listFilter.value" >
<item [item]="item" (onGetDetails)="onGetDetails($event)"></item>
</div>
但是我收到了这个错误:
EXCEPTION: Template parse errors:
Can't bind to '@AnimationState' since it isn't a known native property ("
<div class="panel panel-default" [ERROR ->][@AnimationState]="item.animateState" (click)="toggleAnimateState()">
<div class="panel-he"): Item@2:35
答案 0 :(得分:0)
如果您使用的是RC4 Angular2,则正确的语法为@AnimationState="item.animateState"