Connect hierarchical JSON using AngularJS

I'm facing an issue where I am attempting to bind JSON with two levels to a div using angular.js. The first level binds correctly, but the second level does not seem to be binding properly. Can someone please provide suggestions on how to adjust the binding in the following example http://plnkr.co/edit/iV72hp6nQMUQh1K082Ej? It appears that the nested binding is not working as expected.

Answer №1

I made some adjustments to your code and now it is functioning properly

<!DOCTYPE html>
<html ng-app>
<head>
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
  <script src="app.js"></script>

  <style>
  .mHeader
  {
  background-color:Black;
  color: Orange;
  width: 200px;
  padding-bottom: 0px;  
  margin-bottom: 0px;
  }
  </style>
</head>
<body> 

<div ng-controller="MeetingsCtrl">
  <div id="div1" style="background-color: Brown; width: 200px;">

  </div>

    <script>
        function MeetingsCtrl($scope, $compile) {
            $scope.itemselected = "None";
            $scope.meetings = [
              {
                  country: 'South Africa',
                  children: [
                      {name: "Horse1"},
                      { name: "Horse2" }
                  ]
              },
              {
                  country: 'Great Britain',
                  children: [{ name: "Horse3" },
                      { name: "Horse4" }]
              },
              {
                  country: 'United States',
                  children: [{ name: "Horse5" },
                      { name: "Horse6" }]
              },
              {
                  country: 'Zimbabwe',
                  children: [{ name: "Horse7" },
                      { name: "Horse8" }]
              }
            ];

            $('#div1').html(
       $compile(
         '<ul><li ng-repeat="meeting in meetings"><a>{{meeting.country}}</a> <ul><li ng-repeat="child in meeting.children">{{child.name}}</li></ul></li></ul>'
       )($scope)
     );
            $('#div1').prepend('<div class="mHeader">Race courses</div>');

        }

    </script>
</body>
</html>

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

Using IMG HTML tags in PHP embedded within JavaScript code

Is there a way to successfully add an IMG src tag in JavaScript to pass the image source to a JavaScript variable 'content' and then have it passed to a PHP variable '$html'? I've attempted this but keep encountering an 'unide ...

Converting Three.js camera rotation.y to a full 360 degrees rotation

Currently, I am attempting to rotate a 2D object in my Three.js scene to correspond with the camera's rotation.y value. However, I have encountered an issue with the radians returned by this value. The rotation seems strange, ranging from 0 to -1.4 ra ...

How does the performance contrast between "skip if condition" and "immediately return"?

Do you know if there is a performance variance between these two functions? function x() { var x = false; if(x == true) { ... Numerous lines, like 1 million ... } } function y() { var x = false; if (x != true) { retu ...

"Ionic offers a seamless integration of both side menu and tabs for enhanced navigation

I am working on implementing a sidemenu and tabs on the same screen in my Ionic app project. Currently, it is almost working, but I need the bottom tabs to be visible at all times while also being able to navigate to other views from the sidemenu without ...

When the form is submitted, any blank inputs and their corresponding hidden fields will be disabled

I created a form that has multiple input fields, and users have the option to enter values or leave them blank. Each input field is accompanied by a hidden input field which contains a specific id unique to the corresponding visible input field. To disable ...

Deleting an element in an Array of objects using Typescript

export class AppComponent implements OnInit { title = 'bucketList'; bucketList: BucketListItem[] = [ new BucketListItem( "Goa Trip", "Travel to Goa" ) ]; ngOnInit() { } onItemAdded(eventData) ...

Is there a way to integrate jQuery and Javascript into a Firefox add-on?

Having trouble creating a new element on the page? After checking both the page and domain during onload, it seems that everything is in order. But how can you successfully create a new element in the correct window page? window.addEventListener("load", f ...

Using Vue.js watchers can sometimes cause an endless loop

I'm working on a unique aspect ratio calculator. How can I ensure my code doesn't get stuck in an endless loop when dealing with 4 variables that are dependent on each other? To address this, I implemented 4 watchers, each monitoring a specific ...

Modifying properties of an array of objects in React Native using JavaScript

I have a scenario where I am using Flatlist to render a couple of boxes. If the "shapes" element's "visible" key is false, the box will be blank. This visibility property is defined in state and I'm not sure if this is the correct approach. Now, ...

The script is malfunctioning on Google Chrome

Below is a script that I have: EXAMPLE : <script> var ul = document.getElementById("foo2"); var items = ul.getElementsByTagName("li"); for (var i = 0; i < items.length; i=i+2) { // perform an action on items[i], which repr ...

Activate jQuery Following an Ajax Request - Extension for Enhanced Navigation Using Ajax - WooCommerce Plugin

After searching extensively, I couldn't find a solution directly related to my issue. My knowledge of jQuery is limited, so I'm hoping the solution is something simple. Here is my situation... • I am using a WooCommerce website and have integ ...

Information within specified dates shows all leaders

Looking to filter data based on Start Date, End Date, and HeadName. The current search query successfully filters between dates but does not properly filter the HeadName column, displaying all results instead. Sno HeadName Date Amount BillNo BillD ...

Utilizing the body in GET requests for enhanced client-server communication

What makes url query strings better than request body values? There are distinct advantages to using url parameters, such as visibility in the address bar and the ability to save requests in the browser history. However, is there more to it? Could reques ...

Can you verify that the client's date and time locale are accurate in JavaScript before proceeding with processing?

For my application, I am seeking the current locale datetime. However, before retrieving the date, it is crucial to verify that the local date and time are accurate. If the user has adjusted the date and time incorrectly on their machine, I must prompt a ...

Issue with updating patch version using NPM standard-version

I have integrated standard-version into my javascript project. I made sure to include the release script in my package.json: "scripts": { ... "release": "standard-version" } However, after adding a commit with the mes ...

Adjust the dimensions of the initial cell

I need to adjust the size of the initial "generated" cell in a grid. The grid is not present in the HTML markup until JavaScript prints RSS information on it, making it difficult to target specific rows or cells directly. Note: The first element is hidden ...

Allowing certain routes to be processed by Groovy while others are managed by react-router v4

I'm currently dealing with a situation where the backend Groovy code contains controllers that render GSP (Groovy Server Pages), while for the frontend we're utilizing react-router v4 to manage routes. The issue that I am facing is that when defi ...

Angular Flot Chart Resizing: A Guide to Dynamic Chart S

I have successfully integrated a Flot chart into my HTML using an Angular directive. Here is how it looks: <flot id="placeholder" dataset="dataset" options="options" height="300px" width="100%" style="width:100%;" ng-disabled="graphLoading" ng-class="{ ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

Implementing relationships in microservices with Prisma and NestJS

Schema for User Management service: model User { id String @id @default(uuid()) username String @unique email String @unique password String } Schema for File Management service: model File ...