AngularJS 1.5.5: A guide to passing arrays to HTML

Is it possible to transmit array JSON data from an AngularJS Controller to HTML?

Below is the HTML code:

<body  ng-app="bookApp">
<div ng-controller="bookListCtr">
<table>
    <thead>
    <tr>
        <th>something</th>
        <th>something</th>
    </tr>
    </thead>
    <tbody>
        <tr ng-repeat="item in items">
            <td><( item.id )></td>
        </tr>
    </tbody>
</table>
</div>

</body>

And here is the AngularJS code:

var bookApp = angular.module('bookApp', []);
bookApp.config(function($interpolateProvider) {
    $interpolateProvider.startSymbol('<(');
    $interpolateProvider.endSymbol(')>');
});

bookApp.controller('bookListCtr', function ($scope, $http) {

    $http.get('http://localhost/client_side/public/book').success(function(data) {
        if(data.s_respond === 200){
            $scope.items = data.data;
            console.log(data.data)
        }

    });
});

This represents the JSON data after using console:

s_respond = 200
data = "[{"id":"7","title":"Seven is my lucky number","link":"/api/v1/items/7"},{"id":"8","title":"A Dance with Dragons","link":"/api/v1/items/8"},{"id":"10","title":"Ten ways to a better mind","link":"/api/v1/items/10"},{"id":"42","title":"The Hitch-hikers Guide to the Galaxy","link":"/api/v1/items/42"},{"id":"200","title":"Book title #200","link":"/api/v1/items/200"},{"id":"201","title":"Book title #201","link":"/api/v1/items/201"},{"id":"202","title":"Book title #202","link":"/api/v1/items/202"},{"id":"203","title":"Book title #203","link":"/api/v1/items/203"},{"id":"204","title":"Book title #204","link":"/api/v1/items/204"},{"id":"205","title":"Book title #205","link":"/api/v1/items/205"}]"

Answer №1

It's important to properly parse the JSON before using it in your code

$scope.items = JSON.parse(data.data);

Here is a helpful link that explains how to do this:

Answer №2

There are two tags indicating a 2-column layout. Consider adding another <div> in your body section.

    <body ng-app="bookApp"> <div ng-controller="bookListCtr"> 
<table> 
<thead>
 <tr> <th>something</th> <th>something</th> 
</tr> 
</thead> 
<tbody> 
<tr ng-repeat="item in items">    <td>{{item.id }}</td> 
<td>something else</td>
</tr> 
</tbody> 
</table> 
</div> 
</body>

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

Responsive design issues with Bootstrap 3 box layout

I am currently working on creating a bootstrap4 layout that includes three boxes arranged side by side on a wide screen. However, my goal is to ensure that if the screen size decreases, the red and green boxes always stay adjacent to each other while the b ...

Identify form submission activity

How can I trigger an action when a form is submitted? var ispostaction = false; $("#myform").submit(function () { ispostaction = true; }); Despite setting up the .submit(function ()), it doesn't seem to be called when the form is submitted ...

Guide on how to package a JSON array inside a container object

Below is my Asp.Net 4.5 Web Api method: public IEnumerable<RCWindsWCFService.uspGetAllStationsResult> GetExtAllStations() { RCWindsWCFService.Service1Client client = new RCWindsWCFService.Service1Client(); IEnumerable<RCWindsWCFService. ...

What causes JSON object properties to be null when sent as an Angular request to the Spring Java backend?

When sending a Post request from both the Angular Application and Chrome Poster, I encountered an issue. Using Chrome Poster, I provided the following information: URL: http://localhost:8080/rentapp/policy Header: content-type application/json Conte ...

The background color changes only on a specific page by selecting a color from the color picker

I created a webpage with a color picker that changes the color of the action bar. However, the action bar color only changes once and I want it to change on all other pages as well. Below is the code I used: <h4>Color Picker</h4> <scrip ...

Oops! There was an unexpected error: TypeError - It seems that the property 'title' cannot be read because it is undefined

HTML document example <ion-header> <ion-toolbar color="danger"> <ion-buttons> <button ion-button navPop icon-only> <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon> </button> ...

How to effectively utilize the combination of select and JavaScript?

I am in the process of implementing a selection feature that allows users to choose between two options: owner or non-owner. Depending on their choice, I want to present them with different sets of questions and allow them to input numerical answers from ...

Checkbox within label fails to trigger ng-change event

Here is an example of my HTML code: <input ng-controller="cboxCtrl" type="checkbox" ng-model="hideCompleted" ng-change="hideChanged()"/> Here is the corresponding controller code: angular.module('simple-todos').controller('c ...

Issue with Material-UI Dialog Reusable Component: No error messages in console and app remains stable

Here is a component I've created for reusability: import { Dialog, DialogContent, DialogContentText, DialogTitle, Divider, Button, DialogActions, } from "@mui/material"; const Modal = ({ title, subtitle, children, isOpen, hand ...

Leveraging jQuery plugins within an AngularJs application

I am currently trying to implement the tinyColorPicker plugin from here in my Angular app, but I am facing difficulties with it. An error message keeps appearing: TypeError: element.colorPicker is not a function In my index.html file, I have included th ...

Unexpected Message Pulled from Array of jQuery

I'm attempting to create an array of strings and then randomly select one to display in a div with the class "quote". Below is the code I've been working with: $(document).ready(function() { var quotes = new Array("hello", "world", "goodbye ...

Having difficulty showcasing API call results in a Vue.js component

I am currently experimenting with Vue.js in an attempt to showcase results from a Wikipedia API call within a component using the v-for directive. However, I seem to be encountering some backend issues that I cannot pinpoint. To access the jsFiddle link, ...

Retrieve four distinct values using only a single text box input and display them individually on separate lines

Is there a way to receive four input values from the user using just one textbox and display them on separate lines? function collectData() { var userInput, i; var textOutput = " "; for (i = 0; i <= 3; i++) { userInput = document.g ...

I'm struggling to understand how to properly utilize the "path" parameter in the app.use() function. The outcome it produces is not what I had anticipated

I am a beginner in express.js and I have been trying to understand how to properly use "path" in the app.use() function. However, when I execute the code as shown below, the result is not what I anticipated and it's quite confusing for me. Can you ple ...

Issue with the positioning of data labels in the top row on Highcharts Gantt chart not following the y offset properly

Currently, I am working on creating a milestone comparison chart where I want the data labels to be positioned above the milestone markers. These data labels consist of two rows of text. To achieve this, I have customized the chart.height property to incr ...

PHP code not being detected by web form

After successfully creating a webform using Laravel on my localhost, I encountered an issue when transferring it to the server. The form no longer recognizes my PHP commands as expected. This is illustrated below. In my working model, my code includes Jav ...

Error encountered while attempting to process a POST request in a Spring Boot RestAPI, resulting in an org.springframework

Check out my code on GitHub at https://github.com/prabhatpankaj/SpringREST_API/ Here is the output: { "timestamp": 1498443503678, "status": 400, "error": "Bad Request", "exception": "org.springframework.http.converter.HttpMessageNotReadableEx‌ception", ...

Map with a responsive grid layout featuring two columns

My layout is currently set up with static markup that creates a flex design with 2 columns. <Row> <Col span={6}>content</Col> <Col span={6}>content</Col> </Row> <Row> <Col span={6}>content</Col> ...

Display HTML using JavaScript/jQuery

I am trying to figure out how to print a document by passing custom HTML code. Below is the code I have tried, but unfortunately it's not working: function Clickheretoprint() { var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes, ...

How can jQuery be used to append an array of objects to an <li> element?

I have a collection of objects that I need to incorporate into the current list items. I am looking to include specific attributes from these objects into the list items. While I came across solutions on StackOverflow, such as: $("#header ul").append(&apo ...