Consider the following HTML
<some-component [input]="something" (change)="update(event)"></some-component>
and the update() function
update(event) {
console.log(event);
this.firebaseRef.update(event.$key, event);
}
this logs:
$exists: function()
$key: "initial"
end: "1.20"
options: Object
start: "0.20"
text: "Dit is een test"
And throws this error
Firebase.update failed: First argument contains a function in property
How do I pass the data from the even without the dollar-sign prefixed properties that have been appended by Angular? I'd prefer to do this without manually constructing a new data object.
It's not a good ideia at all, but you can loop through the object properties and filter those which doesn't start with $ or are functions as well. But I recomend you to change the way your event is sending data to the handler, so then you don't have to sanitize extraordinary cases.
function getObjectWithoutDollarSignNameAndFunctions(obj){
var keys = Object.keys(obj).filter(function(key){
return typeof obj[key] !== 'function' && key.indexOf('$') !== 0;
});
return keys.map(function(key){ return obj[key] });
}
var myObject = {
$angularKey: 1,
normalFunction: function(){},
normalKey: 1,
normalKey2: {a:12}
};
var myNewObject = getObjectWithoutDollarSignNameAndFunctions(myObject);
console.log(myNewObject);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With