如何摆脱 angularjs 输出中的大括号并在显示后清除屏幕
How can I get rid of the curly bracket from angularjs output and to clear the screen after the display
我以为我终于明白了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>
我以为我终于明白了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>