Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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?

share|improve this question
    
can you add a plunker or fiddle? –  Mritunjay Aug 5 '14 at 3:05
    
When you use ng-bind you can remove "{{" –  PSL Aug 5 '14 at 3:05
    
same thing even when i removed them! –  RogerFederer Aug 5 '14 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 –  PSL Aug 5 '14 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/… –  Mike Cheel Aug 5 '14 at 3:11

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
hi. i have one more question here for which i would appreciate some help: stackoverflow.com/questions/25131004/… –  RogerFederer Aug 5 '14 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.