2017-06-29 38 views
0

是否有任何方法在角2(v.2.4.0)使循環,或forEach循環從類的每個對象?我的意思是角度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,謝謝:)

回答

2

你可以做到這一點,

for (let item of this.registrationSharingData){ 

} 

,因爲要檢查對象裏面,你不需要一個循環,

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

類型'RegistrationDataInterface'不是數組類型或字符串類型。 –

+0

是不是一個數組? – Sajeetharan

+0

不,很抱歉,我不清楚我需要從一個類中選擇所有項目(名字,姓氏等),而不是從類數組中+我編輯我的示例代碼 –