Which browser do you see the problem?
A similar question was asked some time ago, which came to the conclusion that this may be relevant to Chrome v43.
Some resources related to the problem:
Presumably, Chrome v43 does not do the following in angular.copy source :
var emptyObject = Object.create(Object.getPrototypeOf(source));
You can try any of the following to make sure that it suppresses your errors (regardless of your browser):
- Do not use
angular.copy , avoiding the deep hours a la $scope.$watch('', fn, true) ( jsbin ) and move on to something like _. cloneDeep ( jsbin ) from lodash when you need to make a deep copy of something. - Return to Chrome v42 (if you're on v43).
- Return to Angular 1.2.28, where
angular.copy does not call the line above. source ( jsbin )
If you want to watch carefully, but avoid angular.copy , I would do something like this (using lodash.merge ):
$scope.$watch(function () { return _.merge(src, dest); }, callback);
another jsbin
This way you will not name angular.copy , and you will still have a "deep view" setting. In my opinion, this is a very naive example, and I have not tested it completely, but I think you can make it look very much like an Angular deep watch with minimal effort.
Disclaimer: I really didn’t dig this deep into what is actually happening in the source of angular.copy , console and / or Chrome v43. This is a slightly gray area, but with the above suggestions I have not yet caused an illegal call.
Kasper Lewau
source share