0

is there any way in angular 2 (v. 2.4.0) to make for loop, or forEach loop taking every objects from class? I mean

export interface RegistrationDataInterface {
first_name: string;
    surname: string;
    used_name: string;
    email: string;
}
export class Smth{
registrationSharingData: RegistrationDataInterface;
 checkOut(){
forEach(item from this.registrationSharingData)
{
    if(item!="null")
    {//dosmth}
}}}

I dont want to make 20 ifs, thanks :)

1 Answer 1

3

You can do this,

for (let item of this.registrationSharingData){

}

since you want to check inside the Object, you don't need a loop,

checkOut(){
   You can just access the properties like this.registrationSharingData.whateverfield
}
Sign up to request clarification or add additional context in comments.

6 Comments

Type 'RegistrationDataInterface' is not an array type or a string type.
is not it an array?
Nope, sorry I wasn't clear I need to pick all the items (first_name, surname, etc) from just 1 class, not from array of classes + I edited my example code
I know that I can access the properties like that :) I just wanted to check my every field using loop or smth, because I dont want to write ifs for every of them, it can be impossible as well.
You can loop through object properties using the for (var key in object) loop. If this fits you I'll post an answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.