我正在尝试使用Angular将动画添加到导航栏中,但显示错误如下:
在appmodule.ts
文件中导入了动画包
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule,ReactiveFormsModule} from '@angular/forms';
import {BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { SliderComponent } from './components/slider/slider.component';
import { HoverEffectDirective } from './directives/hover-effect.directive';
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
SliderComponent,
HoverEffectDirective,
],
imports: [
BrowserModule,
AppRoutingModule, FormsModule,ReactiveFormsModule,BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
创建了一个单独的animation.ts
文件并按如下所示进行导出:
import { trigger,animate,transition,style} from '@angular/animations';
export const fadeInAnimation =
trigger('fadeInAnimation',[
transition(':enter',[
style({opacity:0}),
animate('.3s' , style({opacity:1}))
]),
]);
最后将动画模块导入home.ts
的home组件中,如下所示:
import { Component, OnInit } from '@angular/core';
import { fadeInAnimation} from '../../animations'
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
animations : [fadeInAnimation],
host : {'[fadeInAnimation]' : ''}
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}