F
F
Felino2018-08-02 09:22:23
Angular
Felino, 2018-08-02 09:22:23

Angular data entry how?

export class FullModel {
    constructor(
      public firstName: string,
      public lastName: string,
      public avatar: string,
      public company: string,
      public title: string,
      public email: string,
      public phone: string,
      public street: string,
      public city: string,
      public zipCode: string,
      public country: string
    ) {
  }
}

@Input()
  member:FullModel[]
  data1:any
  search='';
  constructor(private peopleService:PeopleService) { }

  ngOnInit() {
     this.peopleService.getPeople().subscribe(data =>
     {
       this.data1=data;
       
       for(let i in this.data1) {
         this.member[i].firstName= this.data1[i].general.firstName;
         this.member[i].lastName= this.data1[i].general.lastName;
         this.member[i].avatar= this.data1[i].general.avatar;
         this.member[i].company= this.data1[i].job.company;
         this.member[i].title= this.data1[i].job.title;
         this.member[i].email= this.data1[i].contact.email;
         this.member[i].phone= this.data1[i].contact.phone;
         this.member[i].street= this.data1[i].address.street;
         this.member[i].city= this.data1[i].address.city;
         this.member[i].zipCode= this.data1[i].address.zipCode;
         this.member[i].country= this.data1[i].address.country;
       }
       console.log(this.member)
     });

Separately, each attribute is output to the console! but when writing to member, it throws an error:
ERROR TypeError: Cannot set property 'firstName' of undefined
at SafeSubscriber._next (list-people.component.ts:25)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber .js.SafeSubscriber.__tryOrUnsub (Subscriber.js:195)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:133)
at Subscriber.push../node_modules /rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:41)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js. FilterSubscriber._next (filter.js:38)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at MergeMapSubscriber.push../node_modules/rxjs/ _esm5/internal/operators/mergeMap.js.MergeMapSubscriber.notifyNext (mergeMap.js:79)
Tell me what to look for?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2018-08-02
@Casufi

In angular, a one-way data flow and mutating an incoming object is an idiotic idea
. And you have a problem because you do not check whether this.member came to you or it is undefined

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question