Running into a strange bug.
I have a form that binds to an object in angular. This object inherits from a base form that contains fields used across all forms, such as FirstName, LastName, etc...
Here is an example of how this is set-up:
myApp.factory('BaseForm', function ()
{
var BaseForm = function ()
{
Object.defineProperty(this, "Foo",
{
get: function () { return BaseForm.Foo; },
set: function (newValue) { BaseForm.Foo = newValue; }
});
}
//Foo is defined as both a static and instance property so value
//can be shared across all instances, but also bound directly in view
BaseForm.Foo= '';
BaseForm.prototype = {
Foo= ''
};
return BaseForm;
});
myApp.factory("ChildForm", ["BaseForm", function (BaseForm)
{
var _base = BaseForm;
var ChildForm = function ()
{
//call the base-level constructor to initialize core properties
_base.apply(this, arguments);
//... other child specific code here...
};
var _childProperties = {
Bar: { enumerable: true, configurable: false, writable: true, value: '' }
};
ChildForm.prototype = Object.create(_base.prototype, _childProperties);
ChildForm.prototype.constructor = ChildForm;
return ChildForm;
}]);
When I submit the form in Chrome, all properties, including those inherited from the base class, are serialized correctly and sent across the wire. The resulting JSON string looks like this:
"{ "Foo": "abc", "Bar": 123 }"
But when I submit the same from in IE (versions 9-11), none of the inherited fields are serialized or sent, and the resulting JSON string looks like this:
"{ "Bar": 123 }"
I have verified that the values are populating correctly in the model, they're just not being serialized in IE. Can anyone help me understand why this is happening and what I need to do to fix it?
Update
So, have not figured out why this is happening, but after reading this post, I added a toJSON() override method in my base class and was able to force this to serialize correctly in all browsers. Not ideal, but was the quickest solution with the least impact to existing code. However, the original question still stands if someone can answer the why part.
Here is a PLUNK demonstrating the behavior:
Thanks!