问题
I have a fresh Ionic project ('blank' template). I have run npm install gsap --save
.
This is my app.module.ts
:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TweenMax } from "gsap/all";
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
TweenMax,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
And this is my home.ts
:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { TweenMax } from "gsap/all";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(
public navCtrl: NavController,
public TweenMax: TweenMax
) {
}
ionViewDidLoad(){
TweenMax.from(".logo", .5, {
opacity: 0,
y: -72
});
}
}
But my app is erroring with:
Runtime error: Can't resolve all parameters for TweenMax: (?, ?, ?).
What's going on here and why am I getting this error? I have tried all of the import types from the npm page and get the same result every time.
回答1:
GSAP TweenMax doesn't provide definition files by default.
npm install --save-dev @types/greensock
Component:
declare var TweenMax: any;
Reference : https://medium.com/@mr.frag85/using-gsap-with-angular-6-project-it-works-on-prod-too-9ac036f21487
Sample Stackblitz : https://stackblitz.com/edit/angular-tkmxb4?file=app%2Fapp.component.ts
For Ionic: please refer GSAP in Ionic project
来源:https://stackoverflow.com/questions/53024864/how-can-i-import-and-use-gsap-in-an-ionic-angular-project