0

I thought I finally understand ng-repeat but now I do not know why the output include the curly bracket and how do I clear the screen after reading the output. Here is part of the output

{"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"}  

but what I really want is just the following without the curly bracket, the word title and the double quotes.

NFL Draft 2020: Over 50 prospects will take part in 'virtual' interviews to air during the event, per report - CBS Sports

and after displaying the list of headlines, I want to clear the screen ( as in "cls" in the command prompt) my angularjs code is this

   $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);

My html is

   <div   ng-repeat="(key, value) in titles">    
    {{value}} 
    </div>
findanswer
  • 35
  • 5
  • https://stackoverflow.com/questions/12866447/prevent-double-curly-brace-notation-from-displaying-momentarily-before-angular-j i find something – Don OzOn Apr 01 '20 at 00:25
  • I tried it before and it did not work for me. It clears the console (as in the development tool) but not the window. – findanswer Apr 01 '20 at 01:35

1 Answers1

0

The syntax you are using is usually used to iterate over properties in an object. Since you already have an array, you can normally iterate over it and display the title value.

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>
nash11
  • 8,220
  • 3
  • 19
  • 55
  • great. It works. Thank you. Now I need to figure out how to clear the window, i.e like "cls" in window . Is it even possible to use jquery? – findanswer Apr 01 '20 at 03:17
  • I figure that out (or a work around). There are several functions for this app, hence I do not want the data to be on the screen. All I need is to set $scope.titles = " " to be the first line in the other options. – findanswer Apr 01 '20 at 03:28