md-chips causes stack overflow when data objects have circular references #5778
Description
The <md-chips>
and <md-contact-chips>
directives can cause a stack overflow when the data objects have a circular reference. This worked up until RC2 when this fix(md-chips): appendChip disallows identical objects #4479 changed MdChipsCtrl.prototype.appendChip
by adding a call to angular.equals()
which doesn't support circular references. Here is a codepen (http://codepen.io/rich-j/pen/RWvymm?editors=101) that shows the issue. Try adding another "person" to the contact chips.
Angular's equals()
function has several unimplemented requests for circular reference support:
- Make angular.equals support objects with circular references #7839
- Bug in angular.equals following #7618 #7724
- making the equals method work when the obj graph has circular refs #9762
- ...and more
Each "person" in our system is a single object that has references to related objects (e.g. parent/child, owner/member). We would like to pass these "person" instances directly to <md-contact-chips>
. The Angular equals()
function does work for object equality (i.e. same object references) however for unequal objects it can get stuck in a cycle since it unfortunately implements a depth first search on object properties.