Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

angular.copy([], obj) will make obj un-clear-able #13193

Closed
codeachange opened this issue Oct 28, 2015 · 1 comment
Closed

angular.copy([], obj) will make obj un-clear-able #13193

codeachange opened this issue Oct 28, 2015 · 1 comment

Comments

@codeachange
Copy link

var arr = []; // got from php like: json_encode(array())
var obj = {};
angular.copy(arr, obj);

after that, both angular.copy([], obj) and angular.copy({}, obj) will not clear the properties of obj. I know that the doc says the destination object should be same type as the source object, but there is no check on that.
It'll be good for debugging if an error would be thrown when the types dose not match.

@jbedard
Copy link
Contributor

jbedard commented Oct 30, 2015

This probably changed a bit after 33c67ce (will be in next 1.5 release). Now the destination object will be cleared correctly, but copying to it will fail in some cases (same cases as before the change).

This could be enhanced a bit to either a) throw an error when isArray(source) != isArray(destination) or b) allow copying from an array into object (just like object into array works today - which is kind of weird)...

@Narretz Narretz modified the milestones: Backlog, Ice Box Nov 2, 2015
Narretz added a commit that referenced this issue Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants