Animation triggers can now be set via template bindings `[]` BREAKING CHANGE: animation trigger expressions within the template that are assigned as an element attribute (e.g. `@prop`) are deprecated. Please use the Angular2 property binding syntax (e.g. `[@prop]`) when assigning properties. ```ts // this is now deprecated <div @trigger="expression"></div> // do this instead <div [@trigger]="expression"></div> ```
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {AUTO_STYLE, Component, animate, state, style, transition, trigger} from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'animate-cmp',
|
|
animations: [trigger(
|
|
'openClose',
|
|
[
|
|
state('*', style({height: AUTO_STYLE, color: 'black', borderColor: 'black'})),
|
|
state('closed, void', style({height: '0px', color: 'maroon', borderColor: 'maroon'})),
|
|
state('open', style({height: AUTO_STYLE, borderColor: 'green', color: 'green'})),
|
|
transition('* => *', animate(500))
|
|
])],
|
|
template: `
|
|
<button (click)="setAsOpen()">Open</button>
|
|
<button (click)="setAsClosed()">Closed</button>
|
|
<button (click)="setAsSomethingElse()">Something Else</button>
|
|
<hr />
|
|
<div [@openClose]="stateExpression">
|
|
Look at this box
|
|
</div>
|
|
`
|
|
})
|
|
export class AnimateCmp {
|
|
stateExpression: string;
|
|
constructor() { this.setAsClosed(); }
|
|
setAsSomethingElse() { this.stateExpression = 'something'; }
|
|
setAsOpen() { this.stateExpression = 'open'; }
|
|
setAsClosed() { this.stateExpression = 'closed'; }
|
|
}
|