I am trying to include animations in my navbar using Angular but its showing the error as below:
Imported animation package in appmodule.ts
file
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 { }
Created a seperate animation.ts
file and exported as below:
import { trigger,animate,transition,style} from '@angular/animations';
export const fadeInAnimation =
trigger('fadeInAnimation',[
transition(':enter',[
style({opacity:0}),
animate('.3s' , style({opacity:1}))
]),
]);
Finally imported the animation module in home component in home.ts
as below:
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() {
}
}