Tips for extracting values from a JSON object in Angular when dealing with a JSON string

Storing column values as a json string in the DB table and then sending them to the front end as a json object.

[  
   {  
      "jobId":"efe0ace0-8ed9-45ff-9232-974cbdc89b86",
      "jobType":"TestExecutionJob",
      "nextRun":"N/A",
      "lastRun":"2015-11-26 13:26:10.664",
      "createdDate":"2015-11-26 13:26:10.664",
      "executor":"sam",
      "JobDetails":"{\"environment\":\"AA\",\"EmailRecipients\":[\"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed9e8c80c39e8c80dcdcad8a808c8481c38e8280">[email protected]</a>\"],\"extraParams\":{\"FileName\":\"myTest.xml\"}}",
      "status":"active",
      "elapsedTime":"18 minutes ago"
   }
]

Incorporated angularJs ng-repeat but nothing is displaying. Need help on accessing JobDetails values (environment, EmailRecipients, and FileName).

<ul><li ng-repeat="t in row.entity.JobDetails">{{t.environment}}</li></ul>

JavaScript File

'use strict';
var tepTableModule = angular.module('test',
        [ 'ngAnimate', 'ngTouch','ui.grid','ngResource' ]).factory('Service',
        function($resource) {
            return $resource('/api/jobs', {});
        });

    tepTableModule
    .controller(
            'tepTableCtrl',
            function($scope, Service) {
                $scope.TestData = Service.query();

                var Plantemplate ='<div><ul><li ng-repeat="t in row.entity.JobDetails">{{t.FileName}}</li></ul></div>';

                $scope.tableData = {
                    data : 'TestData',

                    groupsCollapsedByDefault : true,


                    enablePinning : true,
                    columnDefs : [ {
                        field : 'jobId',
                        displayName : 'jobId',
                        visible : false
                    },  {
                        field : 'JobDetails',
                        displayName : 'Plan Name',
                        cellTemplate : Plantemplate,
                        visible : true
                    },
                     {
                        field : 'jobType',
                        displayName : 'JobType',
                        visible : true
                    },
                     {
                        field : 'environment',
                        displayName : 'Environments',
                        visible : true
                    },
                     {
                        field : 'status',
                        displayName : 'Status',
                        visible : true
                    },
                    {
                        field : 'elapsedTime',
                        displayName : 'LastRun',
                        visible : true
                    },
                    {
                        field : 'JobDetails.EmailRecipients',
                        displayName : 'Email Recipients',
                        visible : true
                    },
                    {
                        field : 'executor',
                        displayName : 'Executor',
                        visible : true
                    }
                    ],
                    sortInfo: {
                          fields: ['elapsedTime'],
                          directions: ['desc']
                        },
                    plugins : [ new ngGridAutoRowHeightPlugin() ]
                };

                $scope.changeGroupBy = function(group) {
                    $scope.gridOptions.groupBy(group);
                }
                $scope.clearGroupBy = function() {
                    $scope.gridOptions.$gridScope.configGroups = [];
                    $scope.gridOptions.groupBy();
                }

            });

HTML

<div ng-controller="tepTableCtrl">
    <div  ui-grid="tableData" class="grid"></div>
 </div>

Answer №1

Convert the string into an object before utilizing it

<script>
 var app = angular.module('myApp', []);
    app.controller('myCtrl', ['$scope', function($scope) {

     $scope.json = [  
         {  
            "jobId":"efe0ace0-8ed9-45ff-9232-974cbdc89b86",
            "jobType":"TestExecutionJob",
            "nextRun":"N/A",
            "lastRun":"2015-11-26 13:26:10.664",
            "createdDate":"2015-11-26 13:26:10.664",
            "executor":"sam",
            "JobDetails":"{\"environment\":\"AA\",\"EmailRecipients\":[\"<a href="/cdn-cgi/l/email-protection\" class=\"__cf_email__\" data-cfemail=\"dfacbeb2f1acbeb2eeee9fb8b2beb6b3f1bcb0b2\">[email protected]</a>\"],\"extraParams\":{\"FileName\":\"myTest.xml\"}}",
            "status":"active",
            "elapsedTime":"18 minutes ago"
         }
      ].map(function(value){
         value.JobDetailParse = JSON.parse(value.JobDetails);
         return value;
      })

    }]);

</script>

Html :

<div ng-repeat = "t in json">
    {{t.JobDetailParse.environment}}
  </div>

Answer №2

Have you considered parsing the information, such as converting it from a string to an object?

newObj = JSON.parse(yourString);

You can then utilize ng-repeat with this new object.

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

What is the best way to insert a hyperlink into the header of a column in a React table that is built using Material

// Here is the header const dataCells = [ {id:"Customer_ID",label:"CustomerId"}, {id:"Type", label: "Type"}, {id:"First_Name", label: "First Name"}, {id:"Last_Name", labe ...

Jest does not support util.promisify(setTimeout) functionality

While I understand there may be similar questions on SO, I believe mine is unique and hasn't been addressed in the current answers. I'm currently experimenting with testing a REST API in Express.JS. Below, you'll find a basic working exampl ...

Modify the background color of a pseudo-element's property value dynamically

How do I change the background color of my burger menu by clicking on an icon? This is the CSS code I have: :root{ --pseudo-backgroundcolor: yellow; } .menu__icon span, .menu__icon::before, .menu__icon::after{ background: va ...

Encountering an abrupt conclusion of JSON input error during a Post request on an API while utilizing an access token in a

When attempting to post user details to an API using the access token obtained during sign up, I encountered the following error message: Unexpected end of JSON input. Here is my code: postNameToApi() { console.log("inside post ap ...

The appearance of a Tom-select with the bootstrap 5 theme sets it apart from a bootstrap 5.1.3 styled select

Premise In order to ensure consistent display of selects across Windows, Linux, and Mac in my project, I have implemented the following combination: tom-select v2.0.1 JavaScript library; Bootstrap v5.1.3 frontend framework; Symfony v5.4.5 backend framewo ...

There seems to be a problem with input/output as the class org.json.JSONObject is missing a serializer and no properties have been found to create

Having trouble understanding the error message that I see: Problem with i/o No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEAN ...

Retrieving device information through JavaScript, jQuery, or PHP

Looking to build a website that can identify the device name and model of visitors accessing the page from their devices. ...

a simplified iteration of jQuery designed specifically for handling ajax requests and JSON data manipulation

While I appreciate the AJAX/JSON features of jQuery, I find that the library is too large for blackberry phone development. Has anyone extracted or created a standalone AJAX/JSON library that is similar to jQuery's? I am aware that a mobile version of ...

Confirm the textarea in a form using jQuery

I am working on creating a plugin for an app that allows users to invite their friends via email, similar to how Dropbox offers extra space for referrals. As a newcomer to JQuery, I'm attempting to validate the single textarea field in my form before ...

Issues with Angular-Trix compatibility with Internet Explorer 10

I am currently using the Angular-trix rich text editor, which is functioning perfectly in all browsers including IE 11. However, I am encountering issues with it not working in IE10 or earlier versions. An error message that keeps appearing states: Una ...

Is there a method to distinguish a true VR HEADSET from a device that simply allows VR capabilities?

I've been on the hunt, but haven't had any luck finding a solution. I'm currently working on a three.js WebGL VR experience and I want to restrict access to VR headsets only, excluding mobile phones. Right now, the only thing I can detect i ...

Extracting information from Semi-Structured Data using Snowflake

I'm attempting to extract the health information from Snowflake's semi-structured data stored in a variant column named extra within table X. An illustration of the code is displayed below: [ { "party": "[{\"class ...

"Use Jquery to automatically scroll back to the top of the page after opening a new window

Currently, when a button is clicked, I am opening a new window that takes me to a specific website. However, in addition to this, I also need the new window to scroll down slightly once it opens. This is how I am currently achieving this: $(document).read ...

Adding a character to an AngularJS textbox

I am attempting to add the "|" Pipe symbol to a textbox when a button is clicked, using this function. $scope.appendPipe = function(){ var $textBox = $( '#synonyms' ); $textBox.val($textBox.val()+'|'); //textBox ...

What is the most effective way to incorporate the Gmail compose window concept into Single Page Applications?

I am currently working on a project that would benefit from a user-friendly way to add transactions quickly. I am intrigued by the idea of creating something similar to the Gmail compose pop-up feature on a single page. I am unsure of how to go abo ...

Ways to continuously refresh the display in AngularJS

There are 2 div elements below, and I need to display only one of them depending on whether the doStuff() function is triggered in the controller when a specific anchor element is clicked. <div ng-controller='myController'> <div ng- ...

The Vue.js array matching method

I am attempting to populate my form with the corresponding values from 'myproduct' where the id_product matches the input. However, when I run the code, the value is not returned. Can anyone spot what's wrong with my code? this.products.forE ...

When using nodejs WriteStream, each write operation is limited to writing a single

My program is supposed to write the contents of an array filled with JSON packets to a specified text file right before exiting. However, it's only writing a single packet to the file instead of all the packets in the array. I have a for loop that ite ...

Using Javascript and Node.js to implement AI: Repeating a word from an array by using matching techniques

Seeking assistance with an AI project involving javascript and Node.js. I have set up hardcoded questions and answers, allowing users to modify the AI's responses. The majority of the javascript code has been implemented on the server-side. I am wor ...

Display picture on webpage in 10 seconds

Hi, I'm working on a website project and I've run into an issue where I need to use JavaScript, but I haven't mastered it yet. I have a background image slideshow set up where a new image appears every 6 seconds. My idea is to have the sec ...