无法绑定到“ fadeInAnimation”,因为它不是“ app-home”的已知属性

时间:2019-11-25 08:22:53

标签: angular angular-animations

我正在尝试使用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() {
  }
}

0 个答案:

没有答案