Unable to Show the Contents of the Item - AngularJS

I'm in the process of developing an application that will showcase job details within a modal window based on the selected template. To achieve this, I've integrated ui.bootstrap and ui.router. However, I'm encountering difficulties in displaying the objects as desired. Even though $http.get seems to be functioning correctly, as evidenced by the object being displayed when I use console.log(specs).

Below is my code:

HTML

<div class="car-up" ng-controller="carCtrl">
     <script type="text/ng-template" id="careersTpl.html">
        <div class="closer">
            <span class="close-me" ng-click="ok()">X</span>
        </div>
        <div class="modal-body">
            <span>{{placeholder}}</span>
        </div>
        <div class="modal-body modtwo">
            <ul>
                <li><a ui-sref="sales">Sales Department</a></li>
            </ul>
            <ul>
                <li><a ui-sref="webd">Web Developer</a></li>
                <li><a ui-sref="crm">Client Relationship Manager</a></li>
                <li></li>

            </ul>
        <div class="show-me" ui-view></div>
        </div>
     </script> 
     <button class="btn" ng-click="open()">Open</button>
</div>

app.js

var app = angular.module('carApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap', 'ui.router']);
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('webd', {
            url: "/web-developer",
            templateUrl: "templates/web-developer.html",
        })
        .state('crm', {
            url: "/crm",
            templateUrl: "templates/crm-uk.html"
        })
}]);

ctrl.js

app.controller('carCtrl', function($scope, $http, $uibModal) {
    $http.get('jobs.json').then(function(response) {
        $scope.placeholder = response.data.default;
        $scope.specs = response.data.specs;

        $scope.open = function() {

            var modalContent = $uibModal.open({
                templateUrl: 'careersTpl.html',
                controller : 'modalContentCtrl',
                controllerAs: '$ctrl',
                size: 'lg',
                backdropClass: 'backdropOver',
                openedClass: 'modal-opened',
                resolve: { 
                    items: function() { return $scope.specs; },
                    items2: function() { return $scope.placeholder;}
                }
            })
        console.log($scope.placeholder);
        console.log($scope.specs);
        console.log($scope.specs.crm);
        }
    });
});

app.controller('modalContentCtrl', function($scope, $uibModalInstance, items, items2) {
    $scope.specs = items;
    $scope.placeholder = items2;
    $scope.ok = function() {
        $uibModalInstance.close();
    }
});

crm-uk.html

<div ng-repeat="(k, v) in specs.crm">
    <h3>{{v["job-title"]}}</h3>
    <p>{{v["job-body"]}}</p>
    Apply Here:
    <p>{{v["job-apply"]}}</p>
</div>

web-developer.html

<div ng-repeat="(k, v) in specs.web-dev">
    <h3>{{v["job-title"]}}</h3>
    <p>{{v["job-body"]}}</p>
    Apply Here:
    <p>{{v["job-apply"]}}</p>
</div>

JSON

{
   "default":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
   "specs":{
      "web-dev":{
         "job-title":"Web Developer",
         "job-body":"Lorem Ipsum Body Text",
         "job-apply":"applink"
      },
      "crm":{
         "job-title":"Client Relationship Manager",
         "job-body":"Lorem Ipsum CRM Text",
         "job-apply":"applylink"
      }
   }
}

I suspect there might be an issue with my .json file or how I am accessing it, but I can't seem to pinpoint the exact problem.

If anyone could offer some assistance, that would be greatly appreciated.

Thank you.

Answer №1

To better structure the JSON data, consider the following format:

{
    "default": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    "specs": {
        "web-dev": [{
            "job-title": "Web Developer",
            "job-body": "Lorem Ipsum Body Text",
            "job-apply": "applink"
        }],
        "crm": [
            {
                "job-title": "Client Relationship Manager 1",
                "job-body": "Lorem Ipsum CRM Text 1",
                "job-apply": "applylink1"
            },
            {
                "job-title": "Client Relationship Manager 2",
                "job-body": "Lorem Ipsum CRM Text 2",
                "job-apply": "applylink2"
            }
        ]
    }
}

Ensure that the "crm" section is structured as a list with multiple items. Then in the view file, you can iterate over the list of "crm" specs.

<div ng-repeat="item in specs.crm">
    {{item['job-title']}}<br/>
    {{item['job-body']}}<br/>
    {{item['job-apply']}}<br/>
</div>

You can also utilize {{::item['job-title']}} for single data binding to optimize performance.

Check out the Plunkr example here. Please note that this update only applies to the 'CRM' section.

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

Unveiling concealed content with JQuery

Here is a link to my pen: http://codepen.io/anon/pen/IszKj I am looking to achieve the functionality where clicking on either "any status" or "any date" will reveal a hidden div containing a list of options. My main query is about the best approach to ta ...

"Encountering a duplicate key error when performing a bulk upsert operation with LoopbackJS and MongoDB

Attempting to perform batch upserts of multiple documents at once using a PUT request to a loopback-based Rest API. The request body consists of an array of JSON objects. [ {"_id" : "1", "data" : "foo" }, {"_id" : "2", "data" : "bar" ...

What is the best way to remove an exported JavaScript file from Node.js?

In my Node.js library package called "OasisLib," there is a file named TypeGenerator.ts. The specific logic within the file is not crucial, but it requires access to files in the filesystem during the project build process. To achieve this, we utilized let ...

Tips for closing 2 models in a React application

Currently, I am working on a project using ReactJs. One of the functionalities I am implementing is generating a user's gallery when the user clicks on their avatar. To achieve this, I am utilizing the react-grid-gallery package along with semantic ui ...

Is it possible to inject $http into an Angular Service and then transfer that data to a controller?

I need assistance with loading JSON data from an external file in AngularJS using a service. myApp.service('ContactsListService', function($http) { var contactsList = $http.get('js/contacts.json').success(function(data){ return ...

Leverage socket.io in various routes within a node.js application

In my Node.js application, I have various routes defined in the router.js file. Now, I want to implement socket.io in every route to enable real-time communication between my Node.js and React.js applications. However, the structure of my Node.js applicati ...

Verify if the array entries match

Within my select element, I populate options based on an array of values. For example: [{ name: 'A', type: 'a', }, { name: 'B', type: 'b', }, { name: 'B', type: 'b', }, { name: &apos ...

What is the best way to incorporate a <li> view cap within a div element using JavaScript?

Currently, I am attempting to implement a dynamic <li> view limit within the content of a div. My goal is to display only 3 <li> elements each time the div content is scrolled. Although not confirmed, I believe this example may be helpful: ...

Click event not functioning in programmatically loaded HTML

I am facing an issue with a JSON file that contains the page content I am trying to load. The link within it appears as follows: <a data-ng-click='foo()'>Bar</a> When I load this page content into the HTML page: <p class="body" ...

Encountering an Uncaught TypeError that is hindering an alert for the score, but I am uncertain about the solution despite the game functioning properly

My Yahtzee code is functioning normally during gameplay, but I'm facing issues with getting alerts for the total score and bonus points. I have identified where the problem lies but I am unsure how to resolve it. I attempted debugging through alerts, ...

Is it possible for Java JSON Parsers to access remote services?

Is it possible to utilize Java JSON Frameworks (such as Jackson, Google GSON, or JSON.simple) for reading JSON data from a remote server? I have a web services server that I need to access to retrieve JSON data and then convert it into a Java object. Curr ...

Strangely unusual issues with text input boxes

So I've set up two textareas with the intention of having whatever is typed in one appear simultaneously in the other. But despite my best efforts, it's not working as expected. Here's the code snippet: <script> function copyText () { ...

loading user input triggers dynamically populated dropdown in react-select

Just getting started with React and experimenting with merging two different functionalities. One involves a dynamic form where inputs can be added or removed, while the other utilizes async react-select for filtering options based on an API source (like c ...

How can I use VueJS Cli to create a shared variable that is accessible across all pages and can be monitored for changes within a specific page?

Recently, I've delved into the world of VueJs and I'm encountering some issues with a project that I can't seem to resolve through online resources. I am trying to establish a variable that is common across all pages (month), and whenever t ...

Deciphering JSON Messages with Python

Currently, I am working on extracting data from a json message and converting it into a python dictionary. The source of the message is the Things Network and I am using the python MQTT handler to receive it. When I print the object, the format looks like ...

Improving efficiency for handling a vast number of inputs in React applications

Dealing specifically with Material UI, I am faced with the challenge of rendering a large number of inputs (more than 100) while effectively managing global state. Performance issues arise when using the Material UI <TextField /> component, with noti ...

Tips for choosing items with protractor generated by ng-repeat and tracked by $index?

I am looking to interact with the textboxes generated by ng-repeat and enter some values using the sendKeys Function. However, I'm uncertain about the approach for selecting these textboxes. Any suggestions on a method to achieve this? Or would it be ...

Executing NodeJS awaits in the incorrect order - When using Express with SQLite3's db.all and db.run, one await is prioritized over the other

Need help running asynchronous functions in .exports, getting promises, and using the results in subsequent async functions. Despite using awaits, the second function seems to execute before the first one. sales.js = const sqlite3 = require('sqlite ...

Modify the text or background shade of the Bootstrap date picker

I have successfully integrated the bootstrap date picker (view figure below) and it is functioning as expected. The code appears like this: <div class="input-group date"> <input name="departure" type="text" class="form-control" id="departure" ...

issue with AJAX POST request not functioning correctly upon form submission

Having an issue with Ajax post while trying to submit a form event. I am working with a table that is generated by opentable.php. Here is the code for opentable.php: <?php session_start(); require("dbc.php"); $memberid = $_SESSION['memberid' ...