Currently, I am utilizing AngularJS and making use of $http.get to fetch a JSON response which I then assign to $scope.myObjects
.
After implementing ng-repeat="object in myObjects"
in the HTML, everything seems to be functioning properly.
My query pertains to manipulating these objects. Is there a method through which I can create a new property named myBoolean
and set it to true
for each object within myObject
?
Upon attempting to manipulate this object in the controller by executing something like:
$scope.myObjects.something
, I encounter an error stating myObjects is undefined
When I attempt to view the JSON response in the browser, all that is visible is [object Object]. Is there a tool available for viewing the JSON response?
EDIT: Here is the HTML snippet:
<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>
Below is the 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;
});
});
Lastly, here is the service code:
angular.module('commentService', [])
.factory('Comment', function($http) {
return {
// get all the comments
get : function() {
return $http.get('/api/comments');
},
});