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

Angular 2 John Papas' Seed Project with simple Apache Server
Angular2 is converting an Array to String
Show page not found in Angular2
Angular2 SELECT OPTION after pipe executes
Angular2 - EXCEPTION: TypeError: Cannot read property 'screen' of undefined
Angular 2: onChanges() is not reflecting Object value changes
How to call ViewChild in runtime?
Angular2 not detecting change to object value
Getting values of looped template using angular2 forms
Breeze and Angular2
Angular 2 hide/show template
Angular 2 RC1 - Auto import all used components inside a base component
Add Lodash to VS2015 Angular2 Project
cannot find module errors after upgrading to angular-2.0.0-rc.4
Angular 2 don't dectect change on an Observable
Convert date in format accepted by restService

Categories

HOME
node.js
objective-c
datatables
java-ee
multidimensional-array
composer-php
data-warehouse
sql-server-2005
https
appium
text
freeswitch
python-3.6
keyboard-shortcuts
terraform
flannel
sourceforge
docbook
alexa-voice-service
tablesorter
pixel
twitter-typeahead
accelerometer
spring-statemachine
robots.txt
firebase-cloud-messaging
mitmproxy
jquery-animate
miktex
robotium-recorder
filenames
ddos
z80
provider
polymer-starter-kit
radius
spring-4
puma
nn
powerdesigner
pi
fancytree
trace
nsset
reduce
dwt
tiles
object-oriented-analysis
dependency-properties
zoo
angularjs-service
sqlcommand
slug
hasownproperty
machinekey
munin
code-signing-entitlements
itil
gm
raptor
post-commit
spoon
qtquick2
antivirus-integration
django-class-based-views
jquery-widgets
sql-server-2008-express
typescript1.7
rich-snippets
ttml
code-completion
grunt-contrib-cssmin
xcode-organizer
iec61131-3
nxt-python
deface
n-tier
raii
parallel.for
dynamic-html
inference
ubuntu-13.04
filtered-lookup
boost-spirit-karma
iunknown
windmill
set-theory
hyperterminal
c89
dvorak
nspasteboard
trx
libjson
progressive-enhancement
pointer-arithmetic

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