如何在 Angular 2 应用程序中使用 fast-json-patch?
How to use fast-json-patch in Angular 2 applications?
我想在 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'
在map
下的system-config.ts
文件中,但在导入时不起作用fast-json-patch
这是我的 system-config.ts
文件的样子:
import * as express from 'express';
import {ng2engine} from 'angular2-universal-preview';
// Angular 2
import {App} from './src/app';
let app = express();
// Express View
app.engine('.ng2.html', ng2engine);
app.set('views', __dirname);
app.set('view engine', 'ng2.html');
// static files
app.use(express.static(__dirname));
app.use('/', (req, res) => {
res.render('index', { App });
});
app.listen(3000, () => {
console.log('Listen on http://localhost:3000');
});
请添加您的代码,以便我查看?
1) 安装包
npm install fast-json-patch --save
2)在要使用ist的组件中,导入需要的函数:
import { compare } from 'fast-json-patch';
3) 创建 Patch 比较旧对象和新对象:
const patch = compare(oldObj, modifiedObj);
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"}
我想在 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'
在map
下的system-config.ts
文件中,但在导入时不起作用fast-json-patch
这是我的 system-config.ts
文件的样子:
import * as express from 'express';
import {ng2engine} from 'angular2-universal-preview';
// Angular 2
import {App} from './src/app';
let app = express();
// Express View
app.engine('.ng2.html', ng2engine);
app.set('views', __dirname);
app.set('view engine', 'ng2.html');
// static files
app.use(express.static(__dirname));
app.use('/', (req, res) => {
res.render('index', { App });
});
app.listen(3000, () => {
console.log('Listen on http://localhost:3000');
});
请添加您的代码,以便我查看?
1) 安装包
npm install fast-json-patch --save
2)在要使用ist的组件中,导入需要的函数:
import { compare } from 'fast-json-patch';
3) 创建 Patch 比较旧对象和新对象:
const patch = compare(oldObj, modifiedObj);
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"}