musicq
V2EX  ›  Angular

求教 Angular2 怎样使用动画

  •  
  •   musicq · Mar 24, 2016 · 4085 views
    This topic created in 3703 days ago, the information mentioned may be changed or developed.

    angular2 怎样使用动画模块

    import {Component,ElementRef,Renderer} from 'angular2/core';
    import {AnimationBuilder} from 'angular2/animate';
    
    @Component({
        selector: 'app-animate',
        templateUrl: `
          <h1 #h1>hello</h1>
          <button (click)="start(h1,button)" #button>开始动画</button>
        `,
        providers: [AnimationBuilder]
    })
    
    export class AnimateComponent {
    
        constructor(public _animationBuilder:AnimationBuilder,
                    public _renderer:Renderer) {
    
        }
    
        start(h1:HTMLElement, button:HTMLElement) {
    
            let origText = button.innerHTML;
    
            this._renderer.setText(button, '动画中..');
    
            this._animationBuilder
                .css()
                .addClass('animated')
                .setDuration(5000)
                .addAnimationClass('bounce')
                .start(h1)
                .onComplete(() => {
                    this._renderer.setText(button, origText);
                });
        }
    }
    

    网上看的这个例子一直报错,就是 providers 这个属性造成的,如果去掉就不会有报错,所以应该怎样写,求教大神!!!!

    1 replies    2016-03-24 11:36:10 +08:00
    musicq
        1
    musicq  
    OP
       Mar 24, 2016
    折腾一上午,终于找到解决方案了!!!真捉急
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5804 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 762ms · UTC 06:31 · PVG 14:31 · LAX 23:31 · JFK 02:31
    ♥ Do have faith in what you're doing.