Ulises Giacoman Ulises Giacoman - 3 months ago 38
Javascript Question

Angular2 RC5 Importing 3rd Party JS Library: Showdown

I'm having trouble importing Showdown as a vendor. When I compile, I get

showdown is not defined
in the browser console. Since it is a vendor package, I don't think I can import it inside of
app.module.ts
. Do I need to declare a custom typing for it? The package is all in
js
. I am running on Angular2 RC5. Thanks!

home.service.ts

import 'showdown/dist/showdown';

declare var showdown: any;

private extractData(res: Response) {
let body = res.json();
var converter = new showdown.Converter(),
originalBody = window.atob(body.content),
body.title = converter.makeHtml(title);
}


vendor.browser.ts

import 'showdown/dist/showdown';

Answer

Solution was to employ typings mentioned by Yakov Fain

import {Converter} from "showdown/dist/showdown";

const converter = new Converter();
var body.title = converter.makeHtml(title);