angular


Angular 2 remove properties prefixed with dollar sign ($) from objects


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);

Related Links

How to Authenticate Angular 2 with Firebase API using Auth0
Include user_metadata and app_metadata in JWT using Auth0
Primeng component calendar have a method for close the pop up calendar manually?
Angular test does not include import from node_modules
Convert Angular 4 web app to Angular Universal app
Generate a routing module while creating a module in angular-cli
What is the best practice to manage sessions with Ionic 2
Angular 2 Updating Component After Form Submit With New Data From Response
How to configure and use Auth-0 in Angular4
How to get meta tags work correctly in angular 2? [closed]
Angular2-highcharts switching option
How to make ViewChild work in a unit test
Angular 2 AOT: Getting lot of errors in index.d.ts
Angular2 doesn't work Custom Reuse Strategy with Lazy module loading
view not updated while changing class variable value angular2
Using Angular 2, how can I allow robots.txt to be viewed without angular routing being triggered?

Categories

HOME
videochat
machine-learning
arduino
magento-1.9
powershell-v4.0
masonry
junit
dfa
ibm-mobilefirst
google-cloud-endpoints
external
rpres
delay
worksheet-function
geometry
delaunay
outlook-redemption
log4net
sapply
restcomm
jquery-gmap3
web-component
spring-boot-actuator
odbc
4d-database
boto
pki
entity-relationship
pex
ebcdic
data-migration
kafka-python
gtm-database
ggiraph
artoolkit
nsdate
javapoet
dexguard
bootstrapping
google-tv
r6
webos
grunt-string-replace
cakephp-2.x
sqlitestudio
behavior
miva
embedded-javascript
satellite
rollbar
jquery-tags-input
munin
volume-rendering
nested-function
virtual-directory
markov-models
ienumerable
oslo
octopress
dynamics-nav-2009
distinct-on
build-dependencies
ti-nspire
undefined-symbol
zshrc
excel-2008
moovweb
joptimizer
certificatestore
pixman
soundex
event-loop
hashbytes
srv
cleartool
unassigned-variable
mux
subsonic2.2
pixate
jform-designer
updatemodel
buttonclick
offlineapps
stubs
where-in
c++builder-6
rs485
eclipse-wtp
cvxopt
file-association
dotfuscator
getprocaddress
nexus-7
system-design
twisted.internet
sqa
ubuntu-9.10
vtl
viewexpiredexception
validationsummary
rakefile
executequery
application-design
sqlmetal

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App