[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;
    }
}
时间: 2024-10-03 13:01:28

[Angular2 Animation] Control Undefined Angular 2 States with void State的相关文章

[Angular2 Router] Lazy Load Angular 2 Modules with the Router

Angular 2 lazy loading is a core feature of Angular 2. Lazy loading allows your application to start up faster because it only needs to use the main App Module when the page initially loads. As you navigate between routes, it will load the additional

[Angular2 Animation] Basic animation

@Component({ selector: 'app-courses', templateUrl: './courses.component.html', styleUrls: ['./courses.component.css'], animations: [ trigger('courseHover', [ state('inactive', style({ backgroundColor: '#eee', transform: 'scale(1)' })), state('active'

[Angular2 Router] Exiting an Angular 2 Route - How To Prevent Memory Leaks

In this tutorial we are going to learn how we can accidentally creating memory leaks in our application while using the Angular 2 router. We are going to learn how we can prove that the memory leak is happening, we are going to learn what is causing

[Angular2 Router] Understand the Angular 2 Base href Requirement

The <base href=”/”/> you define will determine how all other assets you plan on loading treat their relative paths. While you’ll most often use / as your base href, it’s important to understand what’s going on in case you need to change how you’re h

Angular杂谈系列2-Angular2升级Angular4指南

什么什么?Angualr4都发布了,之前不都才Angualr2的么?又要推翻重来,啊? 那当然不是,Angualr4只是一个版本号而已,本质上还是Angular2:以后,谷歌把新版本的Angualr称为Angualr,而之前的1.x版本叫做AngualrJs1.x. Angualr4的更新内容大致包括以下几个方面.       1.更小.更快 新的版本下,打包的文件将更小,运行也更快. 2.AngularUniversal AngularUniversal也就是在服务器端渲染Angular 3.

Jerry的碎碎念:SAPUI5, Angular, React和Vue

去年我去一个国内客户现场时,曾经和他们IT部门的一位架构师聊到关于在SAP平台上进行UI应用的二次开发时,UI框架是选用UI5还是Vue这个话题. 我们代表SAP, 向客户推荐使用UI5是基于以下六点原因: Fiori consists of a large number of UI controls aimed at Enterprise application developed by top JavaScript developers in SAP. Those UI controls p

javascript中null和undefined的区别到底是什么?

8年前我开始学习js的时候,对我来说比较诡异的一个事情是undefined和null都代表空值.那么他们之间明确的不同点是什么呢?他们都能去定义空值,而且null == undefined的值也是TRUE. 大部分现代语言像Ruby,Python,或者Java都只有一个空值nil 或者null,  这是很明智的方法. 而js中,如果一个变量或者一个对象没有进行初始化,(编译器)就会返回一个undefined. 例如: let company; company; // => undefined l

Angular2 小贴士 RouterLink 导航

AngularJS的路由一直是学习的一大难点,我们只能边看边学边掌握,边看边学边推翻.今天我们来看一下在angular2中通过routerLink实现导航的几种方式,以及各自的优缺点. Angular2的路由模块来自@angular/router,这不包含在angular2的核心模块中.所以如果我们想要学习angular2的路由功能,必须导入该模块. 我们自己的最佳实践就是不断的推翻自己的过程,痛苦并痛苦着. 我自己总结的几种导航方式: 1 <a routerLink='/dashboard/h

关于react和Angular的思考

最近react在github上大有赶超 angular的趋势,不得不说前端技术真是日新月异,比起 java c# php等老牌后端语言来说,javascript库的生命周期正在不断的被缩短和别挑战,距离angular发布至今也不过几年的时间,着实让人感叹. 网上一直有人试图拿react与angular作比较,就好比拿facebook和google作比较,两者虽然同样知名,不过显然不是一回事. 就我个人的感触而言,react无疑是一种ui组件化的解决方案,从设计思路上react和目前还是草案的we