I know this question has already been asked, but I can’t find a solution for my specific case. I can not understand the true cause of the error.
I have an angularjs2 application that works fine. Now I would like to import the library marked.
What I've done:
npm install marked
tsd install marked --save
and tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"marked/marked.d.ts": {
"commit": "cc3d223a946f661eff871787edeb0fcb8f0db156"
}
}
}
now trying to import "marked" into my component
import {Component} from 'angular2/core';
import * as marked from 'marked';
@Component({
selector: 'blog-component',
templateUrl: 'app/components/blog/blog.html'
})
export class BlogComponent {
private md: MarkedStatic;
constructor() {
this.md = marked.setOptions({});
}
getMarked() {
return this.md.parse("# HELLO");
}
}
This line: this.md = marked.setOptions({});throws an error with SyntaxError: Unexpected token. Deleting this line does not end with an error. I also want to MarkedStaticbe imported. but then it is impossible to parse the markdown, because it must first be initialized with setOptions.
, , marked , setOptions . , ...
script index.html:
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/typescript/lib/typescript.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script src="node_modules/marked/marked.min.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}}
});
System
.import('app/boot')
.then(null, console.error.bind(console));
</script>