Attaching JSON data to AngularJS form fields

I have received some JSON data in this format:

[{
    "Id": 0,
    "Text": "Item 1",
    "Selected": 1
}, {
    "Id": 1,
    "Text": "Item 2",
    "Selected": 1
}]

Additionally, there is an input element as follows:

<input type="text"
 value="{{question.postObjs}}"

What I am aiming to achieve is to display the values of the "Text" property from the JSON data as a list within the input field.

Item 1, Item 2, ...

Is it possible to accomplish this task? I have been experimenting with different approaches without success so far.

Answer №1

Within your controller:

let newText = '';    
for (let val in scope.question.postObjs){
    newText = newText + val.Text;
}

Incorporate into your input field:

<input type="text" value="{{newText}}" />

Alternatively:

<input type="text" ng-model="newText" />

Answer №2

Create a function in your AngularController as shown below

$scope.getList(){
   // this function will output ["Element1", "Element2"]
}

You can then call this function in your view to display the values.

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

a guide on adding multiple variables into an array in a React Native application

I have a list of 6 variables with corresponding values that I need to push into the "socialMediaDetail" array in a specific format. Can someone please help me with this example? Thank you. // List of 6 variables const Twittername = 'twitter'; co ...

Unable to establish connection through MQTT 1884 protocol

Currently, my website's messaging system is powered by MQTT. While everything is functioning smoothly on my local machine, I encounter an error when trying to use the system on the production site: vendor.bbaf8c4….bundle.js:1 WebSocket connection ...

Using MUI with React Hook Form: Initially fill out the TextField value, only to find it unmodifiable thereafter

Utilizing the MUI + React Hook Form combination, I've developed a CustomTextField.tsx component to ensure smooth functionality. // CustomTextField.tsx import { TextField } from "@mui/material"; export default function CustomTextField(props: ...

Guide on incorporating amcharts into a Nuxt application

I am attempting to integrate amCharts into my Nuxt project. Within the svg-map.vue component, I have added the following code snippet: head() { return { script: [ { src: 'js/amcharts/core.js' } ] }; }, However, I e ...

Having trouble reaching the app.set variables?

Currently, I am developing a web app using expressjs. I am trying to figure out how to pass the port on which the app is running from the callingScript to the module: callingScript.js const http = require('http'); const app = require('./m ...

Obtain the `react-router` Redirect from a collaborative component library

I'm currently working on a component library in (React) that I plan to share. One of the components I want to include is the PrivateRoute. However, I face an error when trying to import this component from the module library into another application: ...

Unexpected Behavior: Angular App Retrieving Entire Collection, Instead of Limited Number of Results

Incorporating observables in my Angular application to fetch data from our API has been a challenging task. Due to the substantial amount of data to be retrieved, we implemented ng2-pagination for efficient pagination handling. The objective was to load sp ...

Meteor: Incorporating New Fields when Creating an Account

Currently, I am experimenting with the Meteor Roles package found at https://github.com/alanning/meteor-roles in order to add a new field to the user model. The user creation process goes smoothly without any issues, however, the 'roles' field t ...

Using React.js to create a modal that includes ExpansionPanelDetails with a Checkbox feature

I am trying to achieve a specific visual effect with my code. Here is an example of the effect I want: https://i.stack.imgur.com/cJIxS.png However, the result I currently get looks like this: https://i.stack.imgur.com/547ND.png In the image provided, y ...

Encountered a surprising issue in JSON parsing with React Native - Unexpected character 'U' at

I encountered an error while retrieving data from an API for my application. Despite successfully obtaining the token, an unexpected error still occurred, even after using AsyncStorage.clear() at the beginning of the app. useEffect(() => { AsyncStor ...

Troubles with Promise.all and json() in JavaScript causing errors being logged as "invalid function"

I'm experiencing some difficulties with the "Promise.all" method. Essentially, I have an array of URLs (here is a simple one if you want to test it: const urlArray = [ "https://coverartarchive.org/release/985adeec-a1fd-4e79-899d-10c54b6af299&qu ...

Using Javascript to Retrieve "Images" from the "Resources" Directory

I typically use Google Chrome as my browser of choice. Unfortunately, the images on certain websites are causing lagging issues. I am looking for a solution to access and clean up these problematic images in order to improve browsing performance. ...

What is the best way to conceal a browser's menu bar?

I'm currently working on an ASP.NET project for an online quiz platform. The questions are being selected randomly from a pool of options. Everything is functioning correctly, but I am looking to restrict users from saving or printing the test by hidi ...

Execute an ajax request when the document is fully loaded using jQuery

Retrieve Cities in Japan using Ajax $(document).ready(function() { $.ajax({ type: 'POST', url: '../include/ListOfCities.php', dataType: "json", data: { Country: "Japan" }, ...

Stylish Output in Flask and uWSGI

When my Python Flask application is running on a development server, it displays JSON calls with pretty print formatting. But once I deploy it to production using nginx/uWSGI, the pretty print is no longer present. Is there a way to preserve the pretty p ...

Unleashing the Power of Postman: Extracting JSON Data for Your RestController

Seeking guidance on REST, can anyone assist me? Question 1: I am currently working with Spring MVC and have configured the dispatcher servlet to handle incoming requests. I am now integrating some RESTful web services into the project - do I need to make ...

Mystery of the Unresponsive MD Ripple Button

While working on creating a CSS button, I wanted to incorporate the Material Design ripple or wave effect into it. I came across a simple script on codepen that works well by adding the class "ripple" to various elements such as divs, buttons, images, and ...

The .removeAttr('checked') method fails to function as expected

I am currently using CodeIgniter. Check out this example of my code. Please fill the textbox and check the checkbox next to it, then click on the "add" link. You will notice that it does not work as expected..removeAttr('checked') newDiv.find(&a ...

Exploring the differences between getJSON and optJSON

As I delved into the documentation for the JSONObject class, I couldn't help but notice the existence of both getJSONObject(String key) and optJSONObject(String key) methods. It seemed to me that these two methods served a similar purpose with one key ...

When attempting to open a native app using JavaScript, it fails to function properly. However, the same code successfully opens the

These questions revolve around a web application developed in React that will be accessed through smartphones' browsers. I conduct testing on an iPhone using both Safari and Chrome. One of the steps involves opening a native authentication app. As pe ...