如何在angular转换为另一个类

时间:2019-07-07 10:49:42

标签: angular casting

这就是我要做的
        我正在尝试将对象转换为不同类的对象         我不知道怎么用短时间做,所以我做了很长的时间         方式,因此没有理由不起作用。         但是我确实犯了一个错误。

    **this is the code, tring to convert**

    loadDev()
    {
      console.log("enter to load dev")
    for(let i=0; i<this.myserv.childListOfCurrentFamily.length; i++)
    {
     this.myserv.compleateChildList[i].Id= this.myserv.childListOfCurrentFamily[i].Id
     this.myserv.compleateChildList[i].IdFamily= this.myserv.childListOfCurrentFamily[i].IdFamily
     this.myserv.compleateChildList[i].Tz= this.myserv.childListOfCurrentFamily[i].Tz
     this.myserv.compleateChildList[i].Name= this.myserv.childListOfCurrentFamily[i].Name
     this.myserv.compleateChildList[i].BornDate= this.myserv.childListOfCurrentFamily[i].BornDate
     this.myserv.compleateChildList[i].Sex= this.myserv.childListOfCurrentFamily[i].Sex
     console.log(this.myserv.compleateChildList[i])
    }
}
    **this is the error, that the convert failed:**
{
    core.js:1598 ERROR TypeError: Cannot set property 'IdFamily' of undefined
        at LoginComponent.push../src/app/login/login.component.ts.LoginComponent.loadDev (login.component.ts:77)
        at SafeSubscriber._next (login.component.ts:101)
        at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:253)
        at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:191)
        at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:129)
        at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
        at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:81)
        at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
        at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (filter.js:85)
        at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)}

0 个答案:

没有答案