Adding Comment feature to a JSON data using AngularJS

admin

Administrator
Staff member
I took an AngularJS test yesterday and I was provided two task.

<ol>
<li>I need to display the data of a JSON file on the web page in HTML form.

<ul>
<li>So I took the FreshlyPressed JSON through the link "<a href="https://public-api.wordpress.com/rest/v1/freshly-pressed" rel="nofollow">https://public-api.wordpress.com/rest/v1/freshly-pressed</a>" and was able to display the thumbnail, post title, content and so on . . on the web page.</li>
</ul></li>
<li>User must be able to post comments on each post.</li>
</ol>

This is where I got stuck since I am not sure if it is possible. Is it possible to add a comment feature to an external JSON data such as the one I used? I just want to know the possibilities and the limitation of the external JSON file. Thank you.

This is my js file

Code:
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);
        };
    }]);

This is my HTML

Code:
&lt;body data-ng-controller="mainCtrl" data-ng-app="myapp"&gt;

&lt;div data-ng-repeat="p in names" class="container"&gt;
&lt;img data-ng-src="{{ p.author.avatar_URL }}"&gt;&lt;br/&gt;
Author: {{ p.author.nice_name }}&lt;br/&gt;
URL: &lt;a href="{{ p.author.URL }}"&gt;{{ p.author.URL }}&lt;/a&gt;&lt;br/&gt;
Title: {{ p.title }}&lt;br/&gt;
Content:&lt;br/&gt;
&lt;div data-ng-bind-html="p.content | to_trusted"&gt;&lt;/div&gt;&lt;br/&gt;
Comments: {{ p.comments_open }}
&lt;/div&gt;
&lt;/body&gt;