如何在Angular 2应用程序中使用fast-json-patch?

Roc*_*cky 4 json json-patch angular

我想在Angular 2应用程序中使用“ fast-json-patch”库(https://github.com/Starcounter-Jack/JSON-Patch)。

我尝试添加:

'fast-json-patch': 'vendor/fast-json-patch/dist/json-patch-duplex.min.js'

system-config.ts在下的文件中,map但导入时不起作用fast-json-patch

Joj*_*elt 6

1)安装包装

npm install fast-json-patch --save
Run Code Online (Sandbox Code Playgroud)

2)在要使用ist的组件中,导入所需的功能:

import { compare } from 'fast-json-patch';
Run Code Online (Sandbox Code Playgroud)

3)要创建补丁,请将旧对象与新对象进行比较:

const patch = compare(oldObj, modifiedObj);
Run Code Online (Sandbox Code Playgroud)

4)打印结果:

console.log(patch);

0:{op: "replace", path: "/firmendetails/registergericht", value: "Darmstadt xx"}
1:{op: "remove", path: "/firmendetails/handelsname"}
2:{op: "remove", path: "/firmendetails/firma"}
3:{op: "remove", path: "/firmendetails/rechtsform"}
Run Code Online (Sandbox Code Playgroud)