ahmed elbarbary

ahmed elbarbary

  • 966
  • 1.5k
  • 106.1k

Value of countrows variable give me undefined although I assign it?

Jul 11 2021 6:51 AM

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


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:

console.log("final data" + data[0].countItems)
give me on console as 
final data 3


Answers (1)