Angular ng-bind is incorrectly displaying the value as 'object' instead of the intended value

I am working on an Angular app where I am retrieving data from a service in the following manner:

angular.module('jsonService', ['ngResource'])
    .factory('MyService',function($http) {
        return {
            getItems: function(profileid,callback) {
                $http.get('/api/myapp/'+profileid+'/').success(callback);
            }
        };
    });

Here is my controller in app.js:

var app = angular.module('myapp', ['ui.bootstrap', 'jsonService']);
    app.controller('mycontroller', function(MyService, $scope, $modal, $log, $http) {
        $scope.profileid=3619;

        MyService.getItems($scope.profileid,function(data){
            $scope.profiledata = data;
        });
    });

The JSON object retrieved in the 'data' variable has the following structure:

[
    {
        "profile_id": 3619, 
        "student_id": "554940", 
        "first_name": "Samuel", 
        "last_name": "Haynes"
    }
]

However, when trying to display these values in a textbox using ng-bind, instead of the actual value, I see [object Object]. This is how I am attempting to bind the student ID in the HTML:

<label for="sid">Student ID</label>
<input type="text" class="form-control" ng-model="profiledata" ng-bind="{{profiledata.student_id}}" />

How can I properly display the values from the JSON object?

Answer №1

Check out this simplified jsbin I created: http://jsbin.com/korufi/1/

Update your input to:

<input type="text" class="form-control" ng-model="profiledata[0].student_id" />

Using ng-bind will result in the input appearing as:

<input type="text" class="form-control">554940</input>

This will not display the student id in the textbox. Stick with ng-model instead.

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

After using browserify, when attempting to call the function in the browser, an Uncaught ReferenceError occurs

I am currently in the process of creating a compact NPM package. Here is a basic prototype: function bar() { return 'bar'; } module.exports = bar; This package is meant to be compatible with web browsers as well. To achieve this, I have inst ...

The unexpected end of input error is caused by an Ajax call that returns a SyntaxError

I recently developed a basic notepad application where users can retrieve a specific file (which essentially translates to a row from MySQL) in order to make edits. When the form is submitted directly to the PHP file without preventing the default behavi ...

What are the best practices for implementing serialization in NestJS?

Recently, I delved into a fresh NestJs project and encountered a hurdle while trying to integrate serialization. The goal was to transform objects before sending them in a network response. Initially, everything seemed to be working smoothly until I attemp ...

Retrieving the link to share for every video located in the Dropbox folder

My Dropbox folder contains a set of videos labeled "v1.avi, v2.avi, ....., vn.avi". I am looking to automate the process of extracting the share link for each video in the folder so that I can easily use it as a source value for HTML video. . . . Is ther ...

Utilizing a dynamic value in an Angular directive

For my latest project, I am working on developing a basic JSON pretty-printer directive using angular.js. Here is the code snippet I have so far: (function(_name) { function prettyJson() { return { restrict: 'E', ...

Accessing a child field from Firebase in a React Native application

My firebase data is structured like this: "Locations" : { "location01" : { "image" : "https://www.senecacollege.ca/content/dam/projects/seneca/homepage-assets/homepage_intl.jpg", "instructorNa ...

Challenges associated with parsing JSON structures that have nested lists and dictionaries

I'm currently in the process of writing a script that will generate a CSV file based on parsed JSON data. While I have successfully managed to read the JSON, I've hit a roadblock with a TypeError: list indices must be integers, not dict. Previou ...

Eliminating unnecessary gaps caused by CSS float properties

I need help figuring out how to eliminate the extra space above 'Smart Filter' in the div id='container_sidebar'. You can view an example of this issue on fiddle http://jsfiddle.net/XHPtc/ It seems that if I remove the float: right pro ...

Changing an Array into JSON format using AngularJS

I am attempting to switch from a dropdown to a multiselect dropdown. <select name="molecularMethod" class="form-control" ng-model="request.molecularMethod" multiple> It is functioning properly. However, when items are selected, it generates an arra ...

Retrieve information from a different JSON dataset using AngularJS when provided with a specific identification number from a related service

I'm currently learning AngularJs and facing a challenge in extracting data from two different JSON API services. I have successfully retrieved a list of user IDs from one service and displayed them. Now, I need to fetch the first name and last na ...

Broaden the natural interface for the element

I'm looking to create a uniquely customized button in React using TypeScript. Essentially, I want to build upon the existing properties of the <button> tag. Below is a simplified version of what I have so far: export default class Button extend ...

Utilizing jQuery for asynchronous image uploading

Just started learning jQuery and I'm having trouble uploading a jpg image file using the ajax method. It seems like it's not working properly. Can anyone guide me through this process? HTML <form action="" method="POST" enctype="multipart/fo ...

Unable to iterate through nested arrays in Contentful mapping

I am facing an issue while trying to map further into the array after successfully retrieving data from Contentful. The error message field.fields.map is not a function keeps popping up and I can't figure out what I'm doing wrong. export defau ...

Instructions on passing a PHP variable as a parameter to a JavaScript function when a button is clicked

In my implementation of codeigniter 3, I have a view page where the data from $row->poll_question is fetched from the database. The different values within this variable are displayed on the voting.php page. Next to this display, there is a button labeled ...

Tips for enabling the OnLoad Event for a React Widget

Hey there! I'm a beginner with React and I'm struggling to call a function once after the component is created. I tried adding an onLoad event in the component creation, but it's not working as expected. The function 'handleClick' ...

I am having issues with Hot Reload in my React application

My app was initially created using npx create-react-app. I then decided to clean up the project by deleting all files except for index.js in the src folder. However, after doing this, the hot reload feature stopped working and I had to manually refresh the ...

Leveraging the power of WCF Data Service and jQuery in harmony for seamless CRUD operations

Exploring WCF data service has opened up new possibilities for enhancing web applications. I am currently experimenting with it, accessing it as demonstrated here. I am aware that the results from WCF data service can be utilized in other .NET application ...

Notation for JavaScript UML component diagrams

When creating connections between entities on a UML diagram, the standard notation is the ball-and-socket/lollipop method. Each pair should include the interface implemented. However, since my project is in JavaScript and doesn't have interfaces, I am ...

Why React.js and webpack are restricting the use of var, let, const?

I'm facing a puzzling issue that I just can't seem to solve. Let me show you a snippet from my Graph.js file: class Graph extends React.Component { @observable newTodoTitle = ""; s = 40 The error in webpack is showing up like this: E ...

How can JSON Jackson utilize a read-only property alias for maintaining backwards compatibility?

We recently discovered a typo in our configuration structure, where the word periodicity was mistakenly spelled as period*o*city. The example source below has been corrected, but we still need to ensure that old configuration files can be read for backward ...