如何使用angular2安装和配置ng2-typewriter?

时间:2017-09-26 02:18:25

标签: angular typed.js

我正在尝试在angular2上安装ng2-typewriter,但我已经用完了选项。我想我已经尝试了书中的所有内容,但它仍然没有用。 有人能帮我吗? 我也尝试过安装和使用typed.js,因为它不起作用

https://www.npmjs.com/package/ng2-typewriter#installation

import { Component } from '@angular/core';
import { TypewriterModule, TypewriterContent, TypewriterService } from "ng2-typewriter";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  name:string;
  contents: TypewriterContent[] = [];
  hobbies: TypewriterContent[] = [];
  isDone: boolean = false;
  constructor(private tws: TypewriterService) {
    this.name = 'Hello Angular2';
    this.contents = this.tws.format(['They say,', 'There are only 10 types of people in the world:', 'Those who understand binary, and those who don\'t.']);
    this.hobbies = this.tws.format(['Java.', 'Javascript.', 'Angular2.', 'Animation.', 'Symphony Music.', 'Movies.'])
  }

  public ngOnInit() {
    this.contents.map((v: TypewriterContent, i: number) => {
      if (i == 1){
        v.setSpecialWord("10");
      }
    })
  }

  onDone( isDone: boolean ): void {
    if(isDone){
      this.name = 'The typewriter is done.'
      setTimeout(() => this.isDone = isDone, 1500)
    }
  }
}

app.module.ts

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    TypewriterModule
  ],
  providers: [TypewriterService],
  bootstrap: [AppComponent]
})
export class AppModule { }

错误

Uncaught Error: Unexpected value 'TypewriterModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

0 个答案:

没有答案