我昨天參加了一個AngularJS測試,並且提供了兩項任務。使用AngularJS向JSON數據添加註釋功能
我需要在HTML表單中的網頁上顯示JSON文件的數據。
- 所以我把FreshlyPressed JSON通過鏈接「https://public-api.wordpress.com/rest/v1/freshly-pressed」,並能顯示縮略圖,標題,內容等。 。在網頁上。
用戶必須能夠在每篇文章發表評論。
這是我被卡住的地方,因爲我不確定它是否可能。是否可以將註釋功能添加到外部JSON數據,例如我使用的數據?我只想知道外部JSON文件的可能性和限制。謝謝。
這是我的JS文件
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);
};
}]);
這是我的HTML
<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>
只需將'comments:[]'屬性添加到要迭代的對象並推送註釋即可。 – tymeJV
我不認爲你會攻擊WordPress.com並改變他們的JSON提要。對您的應用程序本地化的評論系統可能沒問題;-) –
Alvaro G. Vicario - 是的,我認爲,我相信JSON文件中提供的內容是您可以在頁面上顯示的唯一數據。正確? – Neil