是否有任何方法在角度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,谢谢:)
答案 0 :(得分:3)
你可以这样做,
for (let item of this.registrationSharingData){
}
因为您想要检查对象内部,所以不需要循环,
checkOut(){
You can just access the properties like this.registrationSharingData.whateverfield
}