vitaminasweb vitaminasweb - 5 months ago 27
Javascript Question

Format AngularJS ng-repeat text obtained from Laravel API

I have a Laravel 5.2 Backend API and a AngularJS Frontend and at some point I perform a laravel validation and return and error if validation fails.

When I iterate trough errors and display them on the frontend I get somthing like this:

["The email has already been taken."]

and I would like to be like this

The email has already been taken.

without the [""] stuff.

My code is:

Angular controller:

if (error.statusText === "Unprocessable Entity") {

$scope.registerErrors =;

Angular template:

<div class="alert alert-warning animated pulse" ng-if="registerError && isLoading === false">
<p ng-repeat="(error, errorText) in registerErrors">{{errorText}}</p>

Laravel controller:

$this->validate($request, [
'firstname' => 'required|max:100|min:3',
'lastname' => 'required|max:100|min:3',
'email' => 'required|email|unique:users|max:255',


enter image description here

Thanks in advance!


because of errorText contain email array and you shown full email array. if email contain multiple error then can try like:

<p ng-repeat="(error, errorObject) in registerErrors">
  <span ng-repeat=" singleError in errorObject">{{singleError}}</span>

or for single error can try like:

<p ng-repeat="(error, errorText) in registerErrors">{{errorText[0]}}</p>

or just assign instead of

if (error.statusText === "Unprocessable Entity") {
     $scope.registerErrors =;