What is the best way to showcase two different arrays' data in a single Angular view?

I have 2 different arrays retrieved from an API with no common FK or any other identifier.

Even though my TypeScript code produces the expected results, the view remains blank.

The debugging results are provided as comments in the code snippet below:

ngOnInit():void {
        this.data.loadShul()
            .subscribe(success => {
                if (success) { //Debug Results: success = true
                    this.cafe = this.data.cafe,//Debug Results: Array(1) 0:{cafe:Array(5),restaurant :Array(5)}
                        this.restaurant = this.data.restaurant;
                }
            });
    }`

This is how my view looks like:

<ul>
    <li *ngFor="let sy of cafe">
        name: {{sy.name}}  
    </li> 
</ul>
<ul style="background-color:red"> 
    <li *ngFor="let mk of restaurants">
        {{ mk.id }}
    </li>
</ul>
I am getting empty LI tags. 

This is a snippet from my JSON data (e.g., Café):

`[
    {
               "cafe": [
            {
                "id": 1,
                "name": "TestCafe  ",
                "style": "dairy cafe"
            },
            {
                "id": 2,
                "name": "cafe test ",
                "style": "vegan"
            },
            {
                "id": 3,
                "name": "AnyCaffe  ",
                "style": "bakery"
            },
            {
                "id": 4,
                "name": "Pastry    ",
                "style": "Breads and \u0086Pastry\u0087"
            },
            {
                "id": 5,
                "name": "Fantastic ",
                "style": "pizza"
            }
        ],`

https://i.sstatic.net/2GkB4.gif

Answer №1

Your code is correct, but you need to make a modification in the HTML like this:

 *ngFor="let sy of cafe[0]?.cafe

This change should result in displaying li tags properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular - issue with subject observable not functioning as expected

In my service SelectorService, I have created a subject and an observable. private eventEligibleApiStatus = new Subject<any>(); public eventEligibleApiStatusUpdated$ = this.eventEligibleApiStatus.asObservable(); I also have a method in which I use s ...

Issue with compatibility of Angular Elements across Chrome and IE11 at the same time

Experimenting with Angular Elements has led me to focus on achieving optimal browser compatibility. However, I have encountered a roadblock where adding an IE polyfill for Shadow DOM breaks the Element in Chrome. Initially, I faced the error 'Failed ...

Dealing with unsuccessful http puts in an Angular4 application

I'm interested in finding best practices for managing a failed PUT HTTP request within Angular4. Here's the scenario: a basic component is trying to update a record by making an API call with a put request. Below are some example code snippets: ...

Incorporate the teachings of removing the nullable object key when its value is anything but 'true'

When working with Angular, I have encountered a scenario where my interface includes a nullable boolean property. However, as a developer and maintainer of the system, I know that this property only serves a purpose when it is set to 'true'. Henc ...

Facing the dreaded "ECONNREFUSED" error when trying to connect NodeJS and InfluxDb

I'm encountering an issue when trying to connect to my InfluxDB instance running in a Docker container. To get the InfluxDB image, I used the following command: docker pull influxdb:2.4.0 When I run it locally using Docker Desktop, everything works ...

Angular 2: Retrieve current currency rates based on your location

When I apply the {{listing.sellPrice | currency : undefined : 0}} code, it only displays the symbol $. However, I would like for the currency to change based on the user's location. For instance, if someone is in Europe, their currency would be shown ...

Uploading files with Angular 4 and Rails 5 using paperclip

I am currently engaged in a project that involves an Angular 4 frontend and a Rails 5 API backend. I'm facing an issue with uploading videos using paperclip, as they are not getting saved to the database for some unknown reason. Despite all the parame ...

Linking Angular 2 Production Mode to the vendor directory

I am currently working on an Angular2 project using the angular-cli npm package. To upload the app to the server, I used the following commands: ng build --prod and ng serve --prod. However, after uploading the dist folder to the server and trying to acc ...

The combination of Next.JS and React Objects is not acceptable as a React child

Summary: Encountering the error Error: Objects are not valid as a React child (found: [object Promise]) while making a fetch request in a Typescript project. Interestingly, the same code snippet works without errors in a Javascript project. Recently, I ...

Troubleshooting Angular: Issues with Table Data Display and Source Map Error

I'm currently tackling a challenge in my Angular application where I am unable to display data in a table. When I fetch data from a service and assign it to a "rows" variable within the ngOnInit of my component, everything seems to be working fine bas ...

Error: Unable to call function onPopState from _platformLocation due to TypeError

After building an angular application, I encountered a strange issue where it runs smoothly in non-production mode but throws an error when running with --prod: Uncaught TypeError: this._platformLocation.onPopState is not a function I have double-checked ...

Looping issue with ForEach in Typscript with Firebase Functions

While browsing through various questions on this topic, I've noticed that the specific answers provided don't quite fit my situation. My query involves converting a Google Firebase RTB datasnapshot into an array of custom objects, each representi ...

Guide to converting a string into an undefined type

I've been working on parsing a csv file: let lines = csvData.split(/\r\n|\n/); let headers = lines[0].split(','); for (let i = 1; i < lines.length; i++) { let values = lines[i].split(','); ...

Show image using Typescript model in Angular application

In my Angular (v8) project, I have a profile page where I typically display the user's photo using the following method: <img class="profile-user-img" src="./DemoController/GetPhoto?Id={{rec.Id}}" /> However, I am considering an alternative ap ...

Asynchronously download static images with the power of NextJS and TypeScript integration

I have a query regarding my website development using NextJS and TypeScript. The site features a showcase gallery and is completely static. Currently, the initial view shows thumbnails of images. When clicking on a thumbnail, the original image is display ...

What is the best way to send props to a child component in JSX with TypeScript?

While passing props to the child, I encountered an error message stating "Property 'isClicked' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes". I defined "isClicked?: boolean" in my code. What additional steps sho ...

Unveiling the Power of Angular 4's HttpClient for Eff

I have encountered an issue with my API, where it returns ISO date that I need to convert into a JavaScript date. Despite using the HTTPClient module for automatic mapping, the data received is not being transformed as expected. While I am aware that it c ...

using multiple directives in combination with export as

<form novalidate class="mt-2" #paramForm="ngForm" [formGroup]="form" (ngSubmit)="onSubmit(form)"> I recently received a helpful tip from Webstorm: https://i.stack.imgur.com/eb5N8.png Does anyone know of a method to access the ngForm instance expor ...

Retrieve the radio button value without using a key when submitting a form in JSON

Looking to extract the value upon form submission in Angular, here is the code: In my Typescript: constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public formBuilder: FormBuilder, public alertCtrl ...

Passing a click event to a reusable component in Angular 2 for enhanced functionality

I am currently working on abstracting out a table that is used by several components. While most of my dynamic table population needs have been met, I am facing a challenge with making the rows clickable in one instance of the table. Previously, I simply ...