Как вызвать удаление массива paranthese при использовании ng-repeat - PullRequest
0 голосов
/ 20 июня 2019

Как вызывать удалить массив paranthese при использовании ng-repeat

 <ul ng-repeat="error in errors">
                <li>{{error}}</li>
            </ul>

, проходя по процессу и входя в li.Должно быть [] только приемлемая строка, как это сделать

["The password field is required."]

["The password confirmation field is required."]

["The temporary password field is required."]

Это ответ массива

{"errors":{"password":["The password field is required
."],"password_confirmation":["The password confirmation field is required."],"temporary_password":["The
 temporary password field is required."]}}

Ответы [ 2 ]

0 голосов
/ 24 июня 2019

Вы можете просто напечатать их следующим образом: -

<ul ng-repeat="error in errors">
  <li>{{error[0]}}</li>
</ul>
0 голосов
/ 20 июня 2019

Похоже, ваш errors объект содержит объекты, у которых в качестве значений есть массивы строк. Вы можете использовать (key, value) со своим ng-repeat и затем вложенным ng-repeat. Например:

angular.module('app', [])
  .controller('ctrl', function($scope) {
      $scope.errors = {
            "password": ["The password field is required."],
            "password_confirmation ":["The password confirmation field is required."],
            "temporary_password ":["The temporary password field is required."]
            };
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <ul ng-repeat="(key, value) in errors">
    <li ng-repeat="error in value">{{ error }}</li>
  </ul>
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...