Yesterday, I completed an AngularJS test that presented me with two tasks.
One task involved displaying the data of a JSON file on a webpage in HTML form.
- I accessed the FreshlyPressed JSON via the link "" and effectively showcased the thumbnail, post title, content, and more on the webpage.
The other task required enabling users to leave comments on each post.
Although I managed the first task smoothly, adding a comment feature to external JSON data such as the one used raised doubts about its feasibility. I seek clarity regarding the possibilities and limitations of integrating a comment section within an external JSON file. Thank you for your assistance.
Below is my JavaScript (JS) file:
var myapp = angular.module('myapp', ['ui.bootstrap']);
myapp.controller('mainCtrl', function($scope, $http) {
$http.get("https://public-api.wordpress.com/rest/v1/freshly-pressed")
.success(function(response) {
$scope.names = response.posts;
});
});
angular.module('myapp')
.filter('to_trusted', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
Here is my HTML code:
<body data-ng-controller="mainCtrl" data-ng-app="myapp">
<div data-ng-repeat="p in names" class="container">
<img data-ng-src="{{ p.author.avatar_URL }}"><br/>
Author: {{ p.author.nice_name }}<br/>
URL: <a href="{{ p.author.URL }}">{{ p.author.URL }}</a><br/>
Title: {{ p.title }}<br/>
Content:<br/>
<div data-ng-bind-html="p.content | to_trusted"></div><br/>
Comments: {{ p.comments_open }}
</div>
</body>