Angular forEach来自类的所有对象

时间:2017-06-29 09:57:32

标签: angular foreach

是否有任何方法在角度2(v.2.4.0)中进行循环,或者forEach循环从类中获取每个对象?我的意思是

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}
}}}

我不想做20 ifs,谢谢:)

1 个答案:

答案 0 :(得分:3)

你可以这样做,

for (let item of this.registrationSharingData){

}

因为您想要检查对象内部,所以不需要循环,

checkOut(){
   You can just access the properties like this.registrationSharingData.whateverfield
}