Show a nested JSON object when the specific key is not recognized

I received the following data from my API:

{
        "id": 82,
        "shortname": "testing2",
        "fullname": "test2",
        "address": "addrtest2",
        "telephone": "380979379993",
        "website": "www.site2.com",
        "sociallinks": {
            "facebook": "fb2.com"
        },
        "foundationyear": "1992",
        "rating": 0.0
    }

My goal is to display the social network column in a material table. Here's the code snippet for the template:

<button mat-raised-button color="primary" (click)="route.navigate(['/addbuildcompany'])">Add</button>
<table mat-table [dataSource]="dataSource"  matSort >

  <!-- Table columns definition -->
  
</table>

Currently, I am able to display the Facebook link in the social network column. However, I want to dynamically show any key name and its respective value. How can I achieve this?

Here is my model class for Buildcompany:

export class Buildcompany {
id?:any;
shortname?:string;
fullname?:string;
address?:string;
telephone?:string;
website?:string;
sociallinks?:string;

foundationyear?:string;
rating?:number;
}

And here is my component class:

import {Component, OnInit, ViewChild} from '@angular/core';
import {Buildcompany} from "../../models/buildcompany.model";
import {BuildcompanyService} from "../../services/buildcompany.service";
import {MatTableDataSource} from "@angular/material/table";
import {MatSort} from "@angular/material/sort";
import { Router } from '@angular/router';
import {Region} from "../../models/region.model";
import {RegionService} from "../../services/region.service";

@Component({
  selector: 'app-buildcompanies-list',
  templateUrl: './buildcompanies-list.component.html',
  styleUrls: ['./buildcompanies-list.component.css']
})
export class BuildcompaniesListComponent implements OnInit {

  // Class properties and methods
  
}

Answer №1

Big thanks to everyone who assisted me in this matter. I have a quick story for you all. This marks my second venture into Angular and the initial task was precisely as I outlined in my inquiry. Initially, I attempted to utilize the key value pipe but encountered an error from my development environment when I tried to implement it using *ngFor. Therefore, I resorted to simply placing it within a div element, which resolved the issue seamlessly.

<div *ngFor="let item of element.sociallinks | keyvalue">
        {{item.key}}:{{item.value}}
      </div>

As for my query now, does the loop functionality in Angular solely function within an HTML element? It's an intriguing discussion point.

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

Looking to incorporate ipcRenderer from Electron into your Angular project? Having trouble accessing variables passed from the preload script?

I am struggling with incorporating ipcRenderer into the 'frontend' code of my electron app. Although I found examples in the documentation that use require, this method is not accessible on the frontend side where I am utilizing Angular. In the ...

What is the best way to mock an internal function within my route using sinon?

Currently, I have my own internal function defined in the greatRoute.ts file: //in greatRoute.ts async function _secretString(param: string): Promise<string> { ... } router .route('/foo/bar/:secret') .get( async (...) => { ...

Decoding JSON Arrays with Newtonsoft in C#

I am struggling to convert this JSON into an object. The concepts of JArray and JToken are proving to be quite confusing for me. I understand that creating a class would help Newtonsoft in mapping the data, but the structure of the objects like: { "a ...

Is it possible to retrieve JSON data from a PHP file using AJAX on a local server, but encounter issues when trying to do the same on an

I am a beginner when it comes to using AJAX and JSON with PHP and MYSQL. The code I have is functioning properly on localhost, but I am not getting any results from the PHP files on 000webhost. I'm wondering if there are any crucial pieces of code tha ...

Rendering a Subarray using Map in ReactJS

I have an object containing data structured like this: [{"groupid":"15","items":[ {"id":"42","something":"blah blah blah"}, {"id":"38","something":"blah blah blah"}]}, {"groupid":"7","items": [{"id":"86","something":"blah blah blah"}, {"id":"49","somethin ...

Troubleshooting Problems with MongoDB's updateOne() Query

Seeking assistance with the upateOne() query in MongoDB. I am encountering an error message stating: "missing } after property list." Despite my best efforts to ensure correct syntax with braces, colons, and commas, I can't seem to identify the issue. ...

Search through a JSON array to find a specific element and retrieve the entire array linked to that element

Recently, I've been working with a json array that dynamically increases based on user input. Here's a snippet of the json code I'm dealing with: [{"scheduleid":"randomid","datestart":"2020-06-30",&quo ...

Is the JSON returned by WCF Data Services incorrect?

Currently, I am in the process of updating a software application that previously utilized jQuery 1.3.2 to interact with a WCF Data Service (also known as ADO.NET Data Services or Astoria) to now work with the most recent version of jQuery (1.4.2). Unfortu ...

How to Retrieve Observable<Record<string, boolean>> Value with the Help of AsyncPipe

My service retrieves permissions for the currently logged-in user as a record. The necessary observable is declared in my TypeScript file as a member variable: permissionsRecord$: Observable<Record<string, boolean>>; When I call the service, ...

Ways to reset a dropdown selection when a switch is turned off

Hey there! I'm facing a bit of a challenge while working on my project using React, TypeScript, Ant Design, and Refine Framework. In my edit.tsx page component, I need to modify a record based on the value of catHasParent fetched from the database. Wh ...

How can I retrieve object data and store it in a variable using PHP?

I've gone through a lot of responses, but I'm still struggling with something. I have an object that fetches data from a file and formats it into an array. Now, I'm trying to pass this data into a variable in the calling file so that I can m ...

Connecting Angular TextArea functionality to the Ctrl-Enter keyboard shortcut

Recently, I've been working on creating a custom functionality for the <textarea> element. My goal is to have the enter key trigger a specific function, while using ctrl+enter will add a new line in the textarea. I've tried looking through ...

Customize JSON response formatting based on specific needs

When returning a JSON response to an API, I am utilizing the json_encode() method. The array includes a key for users that can contain multiple users, or be empty, and a key for course that can either be empty or contain a single object as shown below: { ...

I possess information stored within the array object below, and I aim to transform it into a different array object format

Here is the response I received from my API: let data = [ { date: '2021-04-27', formatted_date: 'Apr 27', location: [ { date: '2021-04-27', formatted_date: 'Apr 27', countr ...

After the form submission, my Next.js component keeps rendering repeatedly in a cumulative manner

I am currently working on a memory game application using Next.js, Node.js, and Express.js. I seem to be encountering an issue specifically with the login page. Initially, there are no issues when submitting the form for the first time. However, after the ...

A class definition showcasing an abstract class with a restricted constructor access

Within my codebase, there is a simple function that checks if an object is an instance of a specific class. The function takes both the object and the class as arguments. To better illustrate the issue, here is a simplified example without delving into th ...

The table is not properly displaying the data even though it is stored in the array and can be seen in the browser console. What could be causing this issue with my

<tr *ngFor="let animal of readAnimal"> <th scope="row">{{ animal.id }}</th> <td>{{ animal.name }}</td> <td>{{ animal.description }}</td> <td>{{ animal.creat ...

Utilizing Vue and TypeScript - Retrieving a Variable Declared in the Data() Method within Another Method

I recently made the switch to using Vue3 with TypeScript after previously working with Vue2 and JavaScript. I am encountering an issue in my IDE where it is showing an error (even though the code itself functions correctly, but may not be entirely accurate ...

Eliminate an element from a jsonb array based on its value

After successfully removing a value from an array for a single record, I now face the challenge of doing it for multiple records. My current obstacle lies in how I am utilizing the subquery, which is meant to return only a single element. It's possibl ...

receiving list items in JSON format rather than XML or Atom

Upon typing the link of a list in my browser, I am able to view all the data in xml/atom format. The screenshot can be found below: https://i.sstatic.net/9jUKV.png In my search for converting this incoming response to JSON, I utilized the "RequestOptionsA ...