在使用ng-repeat时如何调用删除数组对象
<ul ng-repeat="error in errors">
<li>{{error}}</li>
</ul>
在整个过程中不断循环并取得进展。应该只有[]个字符串是可以接受的。
["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."]}}
答案 0 :(得分:0)
您的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>
答案 1 :(得分:0)
您可以像下面这样简单地打印它们:-
<ul ng-repeat="error in errors">
<li>{{error[0]}}</li>
</ul>