Search code examples
angulargsap

How to import TimeLineMax into my angular2 component?


My component looks like this:

 import {Component} from 'angular2/core';
//import {TL} from 'angular2/TimelineMax';
@Component({
    selector: 'opning',
    templateUrl: './components/opning/opning.html',
    styleUrls: ['./components/opning/opning.css']
})
export class OpenCmp {
    constructor() {
        console.log("played");

        var tl = new TimelineMax();
        var logo = $("#logo");
        tl.from(logo, 4, { z: 500, y: 74, visibility: "visible" });
        //tl.from(logo, 2, { left: "632px" });
        tl.play();

    }
}

My TimeLineMax.min.js is loaded my my main index.html trough a .ts script and gets loaded fine. I just need to import timelinemax so i can use it in my component class. Cant find any examples on this.


Solution

  • I found the solutions via greensocks forums.

    I include the TimelineMax.min.js and TweenLite.min.js in main index.html not using systemjs loader but just loading like normal, then in my component:

    import {Component} from 'angular2/core';
    import "gsap";
    @Component({
        selector: 'opning',
        templateUrl: './components/opning/opning.html',
        styleUrls: ['./components/opning/opning.css']
    })
    export class OpenCmp {
        constructor() {
            var obj = $('#logo');
            var cl = $('#myTab');
            var tbc = $('#tbc');
            var tl = new TimelineMax({ delay: 0.1 });
            tl.from(obj, 0.4, { y: -200 });
            tl.from(cl, 0.3, { x: -1700 }, "=-0.4");
            tl.from(tbc, 0.5, { opacity: 0 });
            tl.play();
            console.log('played');
        }
    }
    

    Now gsap works fine in Angular2