Ways to output a string array from a JSON object containing additional attributes

On the client side, I have received a JSON object from a REST service. This object contains multiple attributes, one of which is a String array. I need guidance on how to display this array using embedded AngularJS code in HTML. Here is my JSON object:

[
    "title": "Developing a System for Information Management in Disaster Relief",
    "url": "http://scholar.google.com/scholar",
    "relatedTitles": 
    [
        "Distributed robotic sensor networks",
        "Improving information access for emergency",
        "Tangible and wearable user interfaces for",
        "Non-parametric inferenc",
        "Airborne near-real-time monitoring of assembly" 
    ]
]

Below is an example of how the ng-repeat looks in HTML.

        
<tr ng-repeat="publication in publications">
        <td>{{publication.title}}</td>
        <td>{{publication.url}}</td>
        <td>{{publication.relatedTitles}} </tr>

Note: "publications" refers to the name of the JSON object

Answer №1

To determine how the information should be displayed when printing, consider the following options:

<tr ng-repeat="publication in publications">
    <td>{{publication.title}}</td>
    <td>{{publication.url}}</td>
    <td>{{publication.relatedTitles.join(', ')}}
</tr>

Alternatively, if you prefer to display each item within a <span> tag, you can utilize another ng-repeat:

<tr ng-repeat="publication in publications">
    <td>{{publication.title}}</td>
    <td>{{publication.url}}</td>
    <td>
        <span ng-repeat="relatedTitle in publication.relatedTitles">
            {{relatedTitle}} 
        </span>
    </td>
</tr>

Answer №2

Utilizing nested ng-repeat directives is possible.

Here's an example of how you can achieve this:

<tr ng-repeat="publication in publications">
        <td>{{publication.title}}</td>
        <td>{{publication.url}}</td>
        <td>
          <table>
            <tr ng-repeat="title in publication.relatedTitles">
               <td>{{title}}</td>
            </tr>
          </table>
        </td>
</tr>

Answer №3

<div ng-repeat="book in books">
    <p>{{book.title}}</p>
    <p>{{book.author}}</p>
    <p>
      <span ng-repeat="genre in book.genres">
        {{genre}}<br>
      </span>
    </p>
</div>

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

When receiveMessage is triggered, the FCM push notification fails to refresh the view

After following this helpful tutorial on Push Notifications with Angular 6 + Firebase Cloud Messaging, everything is working perfectly. I am able to receive notifications when using another browser. To ensure that my notification list and the length of no ...

Utilize jQuery to refresh the database with the information retrieved from the ajax-request

I am attempting to update the database. This is what I am doing From my JavaScript code var data = { "jobid": $('#jobid').val(), "names": $('#names').val(), "scripttype": $('#testscripts').val() }; var msg=""; f ...

Accessing a subdocument in MongoDB using its ObjectID directly

Looking at this arrangement: /* 0 */ { "_id" : ObjectId("53f1f19a477aa5da607b20a4"), "name" : "Anna" } /* 1 */ { "_id" : ObjectId("53f1f192477aa5da607b20a3"), "name" : "Josh", "mother" : ObjectId("53f1f19a477aa5da607b20a4") } Is ther ...

Ignoring templateUrl in AngularJS and Karma-Jasmine to prevent the occurrence of "Unexpected request: GET .../.html" error

Currently, I am developing an AngularJS application using ES6 in order to minimize the amount of work needed for transitioning to AngularJS 2.0. However, I have encountered some complexity when it comes to performing unit tests. My main focus now is to t ...

What is the best way to create a circular to square gradient and save it within a two-dimensional array?

Can anyone guide me on creating a circle/square gradient and storing the data in a 2D array? I want to incorporate this gradient with simplex-noise to develop a procedural island by subtracting the gradient from the generated noise. Here are some visual re ...

Updating dependencies of dependencies in npm: A step-by-step guide

I'm puzzled by the fact that I can't seem to find a solution to this seemingly easy question. It's surprising that even running npm update doesn't resolve the issue. While I can't post my entire dependency tree here, I'll do ...

Steps to trigger a modal (bootstrap 5) in react upon clicking a cell within the Full Calendar interface

My goal is to trigger a modal window using Bootstrap 5 (not React-Bootstrap library) when clicking on a day in the FullCalendar Component in React. I attempted to access the modal by using jQuery's $, but encountered the error message "$ is not a fun ...

What is the most effective way to eliminate error messages from the email format checker code?

Recently, I've been working on a code to validate forms using javascript/jquery. One particular issue I encountered was related to checking email format. The problem arose when entering an invalid email - the error message would display correctly. How ...

Is it possible to create a webpage where the header and footer remain static, while the content in the body can be dynamically changed

I am in the process of creating a webpage where main.html will load a page with a static header and footer that remains unchanged when navigation links are clicked. I'd like to achieve this using Javascript, with the body content being sourced from an ...

Tips on utilizing the event.preventDefault() method within AngularJS?

Recently, I stumbled upon a technique to prevent page refreshing after submitting a form by using event.preventDefault();. As someone who is still learning Angular, I am unsure of how to incorporate this syntax into my Angular controller. Is "event" some s ...

Instructions on dynamically positioning a collection of div elements at the center of a webpage container

I am looking to create a set of divs that are centered on the page and adjust in size according to the length of the username. .Container1 { display: table; width: 100%; padding:0; margin:0; -webkit-box-sizing: border-box; -moz-box-sizing: bor ...

Changing the CSS property from "display: none" to "display: block" using JavaScript causes all the div elements to overlap

My issue involves several radio inputs where clicking one should reveal a hidden div containing information. However, when this div appears, it overlaps with the footer instead of staying positioned between the footer and radio input as intended. I am str ...

Is it necessary to sanitize input fields manually in Angular 6?

Is it necessary for me to manually sanitize all user inputs, or does Angular handle this process automatically? In my login form, the data is sent to the server upon submission. Do I need to explicitly sanitize the data, or does Angular take care of sanit ...

What is causing the UI to change every time I add a tag to refresh the web view?

Recently, I added a pull-to-refresh feature to my React Native webview app using the react-native-pull-to-refresh library. After implementing the tag, I noticed that the UI got rearranged with the webview shifted down and the top half occupied by the pull- ...

Refreshing the Title and URL for a Clutter-Free Look

In my coding project, I am utilizing a method for naming objects in MongoDB through the URL and ui-router functionality. "2000-risk-global-domination"/ After updating the object using Angular Resource, I have made sure to adjust the clean name within the ...

Which specific event in NextJS is triggered only during the initial load?

I am working on a NextJS app and I want to implement an initial loading screen that only appears during the first load. Currently, the loading screen pops up not only on the initial load but also whenever a link is clicked that directs the user back to the ...

Utilizing fluent-ffmpeg in nodejs and express to effortlessly download a video

I've been recently tackling a side project that involves downloading videos from Reddit. The tricky part is that the video and audio are stored in separate files, requiring me to merge them before being able to download them onto the client's dev ...

Adjust the range directly in ng-repeat from the directive

I am working with HTML code that looks like this: <div dir-paginate="x in comments | itemsPerPage: commentsPerPage"> HERE IS DIRECTIVE FROM BLEOW </div> My goal is to update the commentsPerPage scope within the directive... Below is a direct ...

Utilizing node-json2html, generate individual HTML tables for each record

I need assistance in consolidating my JSON data into a single HTML table, instead of generating separate tables for each record through my current transformation process. var data=[{"name":"aa","mid":"12345","user":"a123","password":"a@123"},{"name":"bb" ...

Error thrown by Jest: TypeError - req.headers.get function is not defined

I have a function that is used to find the header in the request object: export async function authorizeAccess(req: Request): Promise<Response | {}> { const access = req.headers.get('Access') if(!access) return Response.json('N ...