javascriptangulartypedjs

How to integrate Typed.js with Angular 2?


I would make a Typewriter effect in angular 2 using Typedjs

As indicated the site page, I have installed the package with npm :

npm install typed.js

Then I have added this code to my component :

import Typed from 'typed.js';// not sure if it's the right way 

and

ngOnInit() {


    var typed = new Typed(".element", {
        strings: ["This is a JavaScript library", "This is an ES6 module"],
        smartBackspace: true // Default value
    });
}

Then in my html file :

<div id="typed-strings">
    <p>Typed.js is an <strong>Awesome</strong> library.</p>
    <p>It <em>types</em> out sentences.</p>
</div>
<span id="typed"></span>

I get this error :

/home/haddad/projects/siteperso/src/app/slide-presentation/slide-presentation.component.ts (18,21): Cannot find name 'Typed'.

PS: i'm open to any other proposition that do the same job as Typed.js and work with Angular 2/4


Solution

  • Try changing your import to import Typed from the typed.js module like so:

    import { Typed } from 'typed.js';