Ng-repeat no JSON data output

I populate a JSON data array with human-related data, for example.

$scope.persons = [{ firstname: '', surname: ''}];
$scope.persons.push({
   firstname: $scope.firstname, //input form field
   surname: $scope.surname //input form field
});

Then I try to output all array elements in HTML as follows:

<span ng-repeat="person in persons">{{person.firstname}} {{person.surname}}</span>

What I get is an empty pair of tags <SPAN>as output, always at the right amount, means: three names in the array lead to three pairs of tags <SPAN>, but there is no user data inside it ?! Why?

+4
source share
2 answers

For some reason, I couldn't figure out the very nature of the problem, but I came across a workaround that helped me. I thought this might be useful for someone else, so here it is:

<ul>
   <li ng-repeat="person in persons">
      <span ng-bind="person.firstname"></span>&nbsp;<span ng-bind="person.surname"></span>
   </li>
</ul>
0
source

- i.e . firstname lastname :

  $scope.persons = [{ firstname: 'Neha', surname: 'Saggam'}];
  $scope.persons.push({
  firstname: $scope.firstname, //input form field
  surname: $scope.surname //input form field
  });

! .

0

Source: https://habr.com/ru/post/1626436/


All Articles