如何在Angular 4中实现diff-match-patchjsDiff

我试过了

import DiffMatchPatch from 'diff-match-patch'

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


并通过绑定

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


但仍然不知道如何将结果绑定到my.component.html。上面的例子效果不好

最佳答案

您可以像这样使用jsDiff:

import * as jsdiff from 'diff'

...

const diff = jsdiff.diffLines(str1, str2)

08-27 22:59