1

I have an angular app where i am getting data from a service as follows:

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

My controller app.js is as follows:

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 i get in the data looks as follows:

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

When i am trying to display these values in a textbox, i do not the the value in it. Instead i get a [object Object] . This is how i am calling the ng-bind in the html doc:

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

How do i display the values from the json object?

8
  • can you add a plunker or fiddle? Commented Aug 5, 2014 at 3:05
  • When you use ng-bind you can remove "{{" Commented Aug 5, 2014 at 3:05
  • same thing even when i removed them! Commented Aug 5, 2014 at 3:07
  • 1
    It seems like profiledata is an array? if so try profiledata[0].student_id. If you want to display multiple records use ng-repeat Commented Aug 5, 2014 at 3:07
  • 1
    What does 'the same again' mean? Make sure you are clearing your cache. Also, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Aug 5, 2014 at 3:11

1 Answer 1

1

Have a look at this simplified jsbin I made: http://jsbin.com/korufi/1/

Change your input to:

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

ng-bind ends up making the input look like this:

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

which will not make the student id show up in the textbox. ng-model will.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.