Angular 离子/角度推动对象到阵列对象

Angular 离子/角度推动对象到阵列对象,angular,object,ionic-framework,Angular,Object,Ionic Framework,我试图将具有值的对象推送到数组,但我总是得到null不是控制台中的对象。但是当我console.log它填充的对象不是null时,为什么我不能将它推入数组 let obj: Lektion; obj = { LektionID: data2.string[0], Date: data2.string[1], StudentID: data2.string

我试图将具有值的对象推送到
数组
,但我总是得到
null
不是控制台中的对象。但是当我
console.log
它填充的对象不是
null
时,为什么我不能将它推入数组

            let obj: Lektion;
            obj = {
                LektionID: data2.string[0],
                Date: data2.string[1],
                StudentID: data2.string[2],
                Name: data2.string[3],
                Status: (data2.string[4] !== '0'),
                TeacherID: data2.string[5]
            };
            console.log(obj);
            this.Lektionen.push(obj);

我认为您在变量和接口上搞混了
Lektion
是一个接口,将其定义为一个变量,并尝试将其推入其中

   let Lektionen = [];
    const data2= {string:[1,2,3,4,5,6]};

    let obj:Lektion = {
                LektionID: data2.string[0],
                Date: data2.string[1],
                StudentID: data2.string[2],
                Name: data2.string[3],
                Status: (data2.string[4] !== '0'),
                TeacherID: data2.string[5]
            };
            this.Lektionen.push(obj);

            console.log(Lektionen); //will print the object

你初始化这个了吗,莱克提奥尼?尝试在推送对象之前初始化它

this.Lektionen = [];
this.Lektionen.push(obj);
理想情况下,在声明变量的位置或要在数组中推送项的函数中初始化它