首页 > 代码库 > [Angular2 Animation] Control Undefined Angular 2 States with void State
[Angular2 Animation] Control Undefined Angular 2 States with void State
Each trigger starts with an “undefined” state or a “void” state which doesn’t match any of your currently defined states. You have to be aware of when you’re in that state so that you don’t stumble on any undesired behaviors. This is especially important if your transitions cover “*”/all states because “void” is part of “all”.
import {Component, trigger, state, style, transition, animate} from "@angular/core";@Component({ selector: ‘app‘, animations:[ trigger(‘signal‘, [ state(‘void‘, style({ ‘transform‘:‘translateY(-100%)‘ })), state(‘go‘, style({ ‘background-color‘:‘green‘, ‘height‘:‘100px‘ })), state(‘stop‘, style({ ‘background-color‘:‘red‘, ‘height‘:‘50px‘ })), transition(‘* => *‘, animate(500)) ]) ], styles:[`.traffic-light{ width: 100px; height: 100px; background-color: black;}`], template: `<div [@signal]="signal" class="traffic-light" *ngIf="isHere" > </div><button (click)="onGoClick()">Go</button><button (click)="onStopClick()">Stop</button><hr><button (click)="onToggleClick()">Toggle</button>`})export class AppComponent { signal; isHere = false; onGoClick(){ this.signal = ‘go‘; } onStopClick(){ this.signal = ‘stop‘; } onToggleClick(){ this.isHere = !this.isHere; }}
[Angular2 Animation] Control Undefined Angular 2 States with void State
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。