I made a component which uses the marked package to render markdown content, the thing is it doesn\'t re-render itself when an async event changes its n
Even if the Günter's answer is great, I wasn't able to resist to create a little plunkr describing how to use Marked into a component: https://plnkr.co/edit/0oSeaIyMWoq5fAKKlJLA?p=preview.
Here are the details:
Marked configuration the HTML file
The component that uses Marked
import { Component, Input } from 'angular2/core';
import marked from 'marked';
@Component({
selector: 'markdown',
template: `
`
})
export class MarkdownComponent {
@Input('data')
data:string;
ngOnChanges() {
this.convertedData = marked(this.data);
}
}
The component that uses the previous Markdown component
import { Component } from 'angular2/core';
import { MarkdownComponent } from './markdown';
@Component({
selector: 'my-app',
template: `
`,
directives: [ MarkdownComponent ]
})
export class AppComponent {
constructor() {
this.markdown = 'Hello';
setTimeout(() => {
this.markdown = `
# Title
Some __test__
`;
}, 1000);
}
}