我以为我终于了解了ng-repeat,但是现在我不知道为什么输出中包含大括号,并且在读取输出后如何清除屏幕。这是输出的一部分
{"title":"NFL Draft 2020: Over 50 prospects will take part in 'virtual' interviews to air during the event, per report - CBS Sports"}
{"title":"Illinois governor says feds sent wrong type of protective medical masks - CNN"}
但是我真正想要的是以下内容,没有大括号,单词标题和双引号。
NFL Draft 2020: Over 50 prospects will take part in 'virtual' interviews to air during the event, per report - CBS Sports
并且在显示标题列表之后,我想清除屏幕(如命令提示符中的“ cls”所示)我的angularjs代码是这个
$http.post('/disdata', " ").then(function(response) {
$scope.answer = response.data;
var titles = [];
for (var i = 0; i < $scope.answer.length; i++) {
titles.push ({
title: $scope.answer[i].title
});
};
$scope.titles = titles;
console.log($scope.titles);
我的html是
<div ng-repeat="(key, value) in titles">
{{value}}
</div>
您正在使用的语法通常用于遍历对象中的属性。由于您已经有了一个数组,因此通常可以对其进行迭代并显示title
值。
angular.module('app', []).controller('Ctrl', ['$scope', ($scope) => {
$scope.titles = [{
"title": "NFL Draft 2020: Over 50 prospects will take part in 'virtual' interviews to air during the event, per report - CBS Sports"
},
{
"title": "Illinois governor says feds sent wrong type of protective medical masks - CNN"
}
];
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="app" ng-controller="Ctrl">
<div ng-repeat="title in titles">
{{title.title}}
</div>
</body>