On 31 December 2013 01:43, Daniel Tabuenca <[email protected]> wrote:

> I'm sure there is plenty of people using angular with grails, but you will
> get a better response if you ask your specific question, since angular
> problems or issues are similar no matter what back-end you use.
>


Ok I try to explain, sorry for my bad english.
I have a form for create a new model, a Supplier, this supplier has many
phones and, in the form, I want to add dinamically as many input fields as
there are the phones to add.
Here is a little piece of the form code:

<span ng-repeat='phone in phones'>
  <input type="text" ng-model="phone.number"
name="phones[{{$index}}].number"">
  <a href='' ng-click='addPhone()'></a>
  <a href='' ng-click='delPhone()'></a>

the angular code is:

$scope.phones = [{name:'phone', number:null}];

    $scope.addPhone = function() {

        var foundNull;
        $scope.phones.forEach( function(phone) {
            if (!phone.number) { // if i.number is null
                foundNull = true;
            }
         });
         if (!foundNull)
$scope.phones.push({name:'phone'+($scope.phones.length + 1), number:null});
    };

    $scope.delPhone = function() {
        $scope.phones.pop();
    };

Now the problem, for those who knows grails, is that there are errors in
the form, then it is render the same form with errors.
When the form is rendered I lost the phones added, that's because
$scope.phones = [{name:'phone', number:null}];
I need a way to maintain the phones added when the form is rendered another
time.
Hope it is clear.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to