Lim Han Yang
Lim Han Yang

Reputation: 440

ERROR TypeError: Cannot read property 'name' does not exist in object

I am having this issue where the code say my property does in the object, but it has already transfer to another object. I am not sure how to solve this. Must I reference the previous object numserve[]?

Html
```                <div class="current">
                    <div class="current-container">
                        <div class="currentvalue">
                            <a>{{serve.data}}</a>
                        </div>
                        <div class="currentname"><a>Currently Serving</a></div>
                    </div>
                </div>```

Typescript
```export class HomeComponent implements OnInit {

  data: any;
  users: Users[];
  did: DID[];

  serve: numserve [] = [];
  constructor(private queueService: QueueService) {}

  ngOnInit() {
    this.queueService.getusers().subscribe(users => {
      console.log(users);
      this.users = users;
    });

    this.queueService.getDID().subscribe(did => {
      console.log(did);
      this.did = did;

    });

    this.serve = this.queueService.getnumserve();
    console.log(this.serve);

    this.queueService.loadNumserve()
    .subscribe(
      (result)=>{
        this.serve = this.queueService.getnumserve();
      });

  }

}

Upvotes: 0

Views: 59

Answers (1)

Prashant Pimpale
Prashant Pimpale

Reputation: 10697

If it is an array and if you want to access first item then you can do it:

<div class="current">
    <div class="current-container">
        <div class="currentvalue">
            <a>{{serve[0]?.data}}</a>
        </div>
        <div class="currentname"><a>Currently Serving</a></div>
    </div>
</div>

Or you can use *ngFor to iterate over an each item:

<div class="current">
    <div class="current-container">
        <div class="currentvalue">
            <span *ngFor="let obj of serve">
          <a>{{obj.data}}</a> 
      </span>
        </div>
        <div class="currentname"><a>Currently Serving</a></div>
    </div>
</div>

Upvotes: 1

Related Questions