var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
result[key] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
}
});
}
return changes(object, base);
}
obj1 ={a:1, b:2}
obj2 ={a:1, b:4}
df = difference(obj1, obj2)
console.log (df)
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script data-require="lodash@*" data-semver="2.3.0" src="https://raw.github.com/lodash/lodash/2.3.0/dist/lodash.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<a href="http://www.mattzeunert.com/2016/01/28/javascript-deep-equal.html">http://www.mattzeunert.com/2016/01/28/javascript-deep-equal.html</a><br />
<a href="https://www.samanthaming.com/tidbits/33-how-to-compare-2-objects">https://www.samanthaming.com/tidbits/33-how-to-compare-2-objects</a><br />
<b><i>this plunk 201811:</i><a href="https://gist.github.com/Yimiprod/7ee176597fef230d1451">https://gist.github.com/Yimiprod/7ee176597fef230d1451</a><br /></b>
<a href="https://gist.github.com/nicbell/6081098">https://gist.github.com/nicbell/6081098</a><br />
<a href=""></a><br />
<a href=""></a><br />
<a href=""></a><br />
<a href=""></a><br />
<a href=""></a><br />
<a href=""></a><br />
<a href=""></a><br />
</body>
</html>
/* Put your css in here */