Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I work on angular 7 I face issue countrows variable give me undefined value

although I assigned it with value as below

Expected result I need is to get value 3 from returned array of object

TypeScript
public Countrows:Number;
ngOnInit(): void {
countitems()
console.log("final count rows is" + this.Countrows);

}
countitems()
 {
  this._inventory.GetcountItems().subscribe(
    data =>this.Countrows=data[0].countItems 

  )
 }
it give me final data  undefined


data returned on variable Countrows

[
    {
        "countItems": 3
    }
]


What I have tried:

TypeScript
console.log("final data" + data[0].countItems)
give me on console as 
final data 3
Posted
Updated 11-Jul-21 22:59pm

1 solution

We can't see how your GetcountItems function is defined. But the fact that you're passing a continuation function to the result suggests it's making an asynchronous request.

You won't be able to access the results of the asynchronous request until the request has completed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900