ng-repeat: generate select options from an array

My JavaScript object is quite simple and looks like this:

$scope.obj = { "'Architect'": ["asdf","d","e","y"]};

I am trying to display the values of 'Architect' in a select box. The issue arises because of the single quotes, making it difficult to use ng-repeat.

<select>
    <option ng-repeat="row in obj['Architect']" value="{{row}}">{{row}}</option>
</select>

Unfortunately, this code does not populate the select box as expected. It seems that the single quotes are confusing the interpretation as a string literal, even after adding escape characters. What could I be overlooking?

Feel free to check out a sample plunker here.

Answer №2

Have you considered using "ng-options" for the select element? Check out this resource for more information: AngularJs API: select

Answer №3

Below is the entire code snippet for implementing ng-repeat with an external JSON file

HTML

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Using jQuery Datatable in AngularJS</title> 
  <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
  <link rel='stylesheet prefetch' href='https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css'>
      <link rel="stylesheet" href="css/style.css"> 
</head>
<body>
  <div class="container" ng-app="problemApp" data-ng-controller="validationCtrl">
  <select>
    <option ng-repeat="item in testdata" value="">{{item.name}}</option>
</select>
</div>
  <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js'></script>
<script  src="js/index.js"></script>
</body>
</html>

index.js

var app=angular.module('problemApp', []);
app.controller('validationCtrl',function($scope,$http){
    $http.get('http://localhost/Dtable_angular/ngrepeatdropdown/test.json').success(function (data) {

                $scope.testdata = data;
                console.log($scope.testdata)
        })


$scope.dataTableOpt = {
   //custom datatable options 
  // or load data through ajax call also
  "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
  };
});

test.json

[{
        "countryId": 1,
        "name": "France - Mainland",
        "desc": "some description"
    },
    {
        "countryId": 2,
        "name": "Gibraltar",
        "desc": "some description"
    },
    {
        "countryId": 3,"name": "Malta","desc": "some description"}]

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

Attempting to showcase a collection of values, specifically focusing on highlighting the even numbers within the array

const sampleArray = [ 469, " " + 755, " " + 244, " " + 245, " " + 758, " " + 450, " " + 302, " " + 20, " " + 712, " " + 71, " " + 456, ...

Navigate to the homepage section using a smooth jQuery animation

I am looking to implement a scrolling feature on the homepage section using jquery. The challenge is that I want the scrolling to work regardless of the page I am currently on. Here is the HTML code snippet: <ul> <li class="nav-item active"> ...

Can someone explain to me how this ternary operator works?

Can anyone demonstrate how to convert this function into a traditional if-else statement? export const orderArr = (arr: any[], key: string) => arr.sort((a, b) => ((a[key] > b[key]) ? 1 : (a[key] === b[key]) ? ((a[key] > b[key]) ? 1 : -1) : -1)) ...

NuxtJs: Oops! It looks like NuxtError is not defined in this context

Exploring NuxtJs is new to me. I decided to experiment with how nuxt-link functions by purposely setting up a nuxt-link to a non-existent route in order to trigger the default 404 page. Here's the line of code I added to the pages/index.vue file: < ...

Can a promise be safely resolved more than once?

In my application, there is an i18n service that includes the following code snippet: var i18nService = function() { this.ensureLocaleIsLoaded = function() { if( !this.existingPromise ) { this.existingPromise = $q.defer(); var deferred ...

Creating a Modal Dialog with Justified Tab and Dropdown Using Bootstrap 4.1

I am struggling with Bootstrap 4.1 as I try to align content to the right side. Specifically, I have a Navigation Bar that triggers a Modal Dialog containing Tabs. The dropdown menu on the far right of the Tab is what I want to justify to the right. Here a ...

Is it possible to transform JSON Array Data from one format to another?

As someone who is new to the software field, I am working with a JSON array of objects: var treeObj = [ { "name": "sriram", "refernce_id": "SAN001", "sponer_id": "SAN000" }, { "name": "neeraja", "r ...

"Cannot access files using jQuery $_FILES array with blueimp file upload plugin in Internet Explorer versions 8 and

While browsing StackOverflow, I noticed numerous questions regarding the Blueimp file upload plugin in IE8/9. Unfortunately, none of them seem to address the specific issue I am facing. Currently, I am using IE10 in IE8/9 simulator mode. However, each tim ...

Tips for monitoring element visibility in PhantomJS

When users click this link: <span onclick="slow_function_that_fills_the_panel(); $('#panel').show();"> I am now simulating the click using phantomjs: page.evaluate( function() { $("#panel").click(); } ); console.log('SUCCESS' ...

Having trouble deploying a Heroku app using Hyper? Here's a step-by-step guide to

After running the following commands: https://i.stack.imgur.com/WZN35.png I encountered the following errors: error: src refspec main does not match any error: failed to push some refs to 'https://git.heroku.com/young-brook-98064.git' Can anyon ...

Determining the Uniqueness of Inputs in AngularJS and Handling Duplicates: A Guide to Invalidating Duplicate Inputs

Currently, I am facing a situation where users need to input data into text areas generated through ng-repeat. The requirement is that if a user enters a value that matches an existing entry, both the new and existing values should be flagged as invalid. A ...

Using JQuery to Update Text, Link, and Icon in a Bootstrap Button Group

I have a Bootstrap Button group with a split button dropdown. My goal is to change the text, href, and icon on the button when an option is selected from the dropdown. I am able to change the text successfully, but I'm having trouble updating the HREF ...

Regular intervals and asynchronous JavaScript and XML (AJAX) requests are

There is a simple chat tool in place to ensure the chat room stays updated: setInterval (loadLog, 2500); function loadLog(){ //Scroll height prior to the request var oldScrollHeight = document.getElementById("chatMessages").scrollHeight - 20; ...

div consistently positioned above fixed element

My goal is straightforward - I have a fixed div at the bottom of my page that always needs to be visible. Inside this div, there are two sub-divs; one small div should always be on top, and the other should be scrollable. The issue lies with the small div ...

Bootstrap dropdown menu appears to be frozen in the open position, unresponsive to the button click

I am currently working on developing a straightforward sign-in program to be used on a podium at my office. The main purpose of this program is to allow clients to input their name, username, description of their issue, and then click submit. Subsequently, ...

When the webpage is reloaded in Internet Explorer, a file is automatically downloading. How can this issue be resolved?

Below is the anchor tag in HTML for downloading a file. <a [href]="myFileUrl" class="u-text--document" download="myfile.csv"><span>Title of the Excel document (6.8MB)</span></a> This method is called on n ...

flexible reaction mechanism for Uploadify

Welcome I am working on a project that involves utilizing two forms within tabs in Ext-JS. Additionally, I am implementing the jQuery framework for my main JavaScript programming tasks. Lastly, I have a global JavaScript object instance (singleton) named ...

Using the ControllerAs syntax in conjunction with $scope methods

Currently working on incorporating the controllerAs syntax into AngularJS 1.3 Here is how I'm starting my function declarations: function() { var myCtrl = this; myCtrl.foo = foo; // Successfully implemented myCtrl.$on("foo", bar); // Enc ...

A guide to implementing bounds with dynamic markers in react-leaflet

I have a functional react component that currently displays two static markers within a bounding box that fits both markers inside. However, I am trying to figure out how to pass an array of latitude and longitude values to dynamically display the markers ...

Oops! There seems to be a problem with the Node.js App. The MongooseError is indicating that the parameter `uri` in the `openUri()` function should be a string,

I've encountered an issue with my Next.js app involving MongoDB that I've been struggling to resolve. Hoping someone here can provide some insight and help me out. This is quite crucial for my project. First, I'll share the code from my serv ...