1

How to implement diff-match-patch or jsdiff in Angular 4?

I've tried

import DiffMatchPatch from 'diff-match-patch'

const dmp = new DiffMatchPatch()
const diff = dmp.diff_main('dogs bark', 'cats bark', null, null)
this.foo = diff

and binding it by

<div [innerHtml]="foo"></div>

but still don't really know how to bind result to my.component.html. Example above doesn't work as well

1 Answer 1

3

You can use jsDiff like so:

import * as jsdiff from 'diff'

...

const diff = jsdiff.diffLines(str1, str2)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.