0

Hi everyone i'm trying to check for example before to create a document on a collection in Firebase, if the object.name, object.title, object.velocity... are just a white space ('') or if they are null in typescript (Ionic 4), but i think there is another way more fast, what is the best recomendation to deal with it?

What i did is, but i think is so long...:

if (this.object.name == '' || this.object.title == ''.......)

Thank you

M. Mariscal
  • 1,226
  • 3
  • 17
  • 46
  • No idea what you are trying to ask... but check this link. https://stackoverflow.com/questions/8217419/how-to-determine-if-javascript-array-contains-an-object-with-an-attribute-that-e – Juan Jun 21 '19 at 10:51
  • Ok now i've updated it, sorry – M. Mariscal Jun 21 '19 at 11:00

1 Answers1

1

Unfortunately my reputation is too low to ask this as a comment.

Where does the object.property gets its value from? Are you using input fields on a form in your HTML?

If you are using a input fields on a form to capture object.name and object.title then it would be easier/best to use form validators with formGroup and formBuilder

import{ Validators, FormBuilder, FormGroup, FormControl }from'@angular/forms';

This will make sure that your object properties always have data in them or it will let you display to the end user that something is wrong with their information.

There is a lot of information out there on validators, but they are rather simple to implement, and it is mostly done on the page.html.

If you are getting your data from a service or just want to check the object 1 last time before you doSomething() then you will need to loop through each of the properties in the object.

Determining if all attributes on a javascript object are null or an empty string

Juan
  • 108
  • 8