RaulGM RaulGM - 1 year ago 106
TypeScript Question

angularfire2 set the title of an object by dynamic data content

is it possible to set the name of an object with a string variable?

For example:

car: {
brands: {
var1: ''

This is the query I imagined would work:

addBrand (var1) {
var brandRef = firebase.database () .ref ().child ('car/brands');
brandRef.set ({
var1: ''

The output I get is the text
, not its value.

Is there any way of achieving this?

Answer Source

You can do this:

addBrand (var1) {
  let brandRef = firebase.database().ref('car/brands'),
      setInfo = {};
  setInfo[var1] = '';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download