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?
profiledata
is an array? if so tryprofiledata[0].student_id
. If you want to display multiple records use ng-repeat – PSL Aug 5 '14 at 3:07