Reputation: 123
I am using regular REST API with Angular like under the link: https://www.techiediaries.com/angular-by-example-httpclient-get/
In the function:
ngOnInit() {
this.dataService.sendGetRequest().subscribe((data: any[])=>{
console.log(data);
this.products = data;
})
}
can we get into data
and get to know how many elements is returned?
I need to know how many elements are returned from backend.
Upvotes: 0
Views: 251
Reputation: 296
If data is an array simply use length property.
ngOnInit() {
this.dataService.sendGetRequest().subscribe((data: any[])=>{
console.log(data);
this.products = data;
this.productsLength = data.length;
})
}
Upvotes: 0
Reputation: 9355
The API returns array data: any[]
. Javascript Array has length
property which shows the total number of items in the array. All you need is to use data.length
. If you are dealing with data, then you probably need to know the basics of Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Upvotes: 2