I am using angular and I am using $http.get to get a JSON response back and I set it equal to $scope.myObjects .
When I use ng-repeat="object in myObjects" in the html, it works.
I wanted to know, is there a way to manipulate these objects? I want to create a property called myBoolean and for each object in myObject set myBoolean to true.
When trying to manipulate this object in the controller by doing something like:
$scope.myObjects.something I get myObjects is undefined
when I try to view the JSON response in the browser all I see is [object Object]. Is there a tool to view the JSON response?
EDIT: here is my html
<div class="comment" ng-hide="loading" ng-repeat="comment in comments">
<h3>Comment <% comment.id %> <small>by <% comment.author %></h3>
<p><% comment.text %></p>
<div class="col-sm-6">
<p><a href="#" ng-click="deleteComment(comment.id)" class="text-muted">Delete</a></p>
</div>
</div>
here is my controller
angular.module('mainCtrl', [])
.controller('mainController', function($scope, $http, Comment) {
$scope.commentData = {};
$scope.loading = true;
Comment.get()
.success(function(data) {
$scope.comments = data;
$scope.loading = false;
});
});
and my service
angular.module('commentService', [])
.factory('Comment', function($http) {
return {
// get all the comments
get : function() {
return $http.get('/api/comments');
},
});
document.write("<p>" +$http.get('/api/comments') + "</p>");I get [object Object]. Also as I wrote in the html when I iterate through the object, i can see it works. Is there a better way than document write? sorry, i'm new at this