角度的Image Slider实现

时间:2019-03-06 09:15:58

标签: angular

Uncaught Error: Unexpected module 'BrowserAnimationsModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.
at syntaxError (compiler.js:2430)
at compiler.js:18700
at Array.forEach (<anonymous>)

当我尝试在我的角度项目中添加图像滑块时,这是错误。

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-imgslider',
  templateUrl: './imgslider.component.html',
  styleUrls: ['./imgslider.component.css']
})
export class ImgsliderComponent implements OnInit {

  imagesUrl;
  constructor() {
   }

  ngOnInit() {
    this.imagesUrl = [
      'https://mdbootstrap.com/img/Marketing/products/angular/mdb-free.jpg',
      'https://cdn-images-1.medium.com/max/1600/1*JIlheWRZjH1loN8eBCDHJA.jpeg',
      'https://i.imgur.com/ycy5LOe.png',
      ];
  }

}

这是我的image.component.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SliderModule } from 'angular-image-slider';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';

import { HomeComponent } from './home/home.component';


@NgModule({
  declarations: [

    BrowserAnimationsModule,
    SliderModule,
    AppComponent,
    HeaderComponent,

    HomeComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

这是app.module.ts

当我尝试在我的角度项目中实现图像滑块时,出现诸如未捕获错误:意外模块之类的错误。我已经在这里附加了我的代码并进行了检查,如果有任何更正,请告诉我。

1 个答案:

答案 0 :(得分:0)

BrowserAnimationsModule应该位于app.module.ts的“导入”中,而不应位于“声明”中。它可能会解决您的问题