0

I have a simple repeater in which each row can be edited in-line. As part of that repeater, when I add a new row I would like it to be in the editable state, not static. When I tried adding the $scope.editable = true to the Add Button, it makes the entire repeater editable.

Here's a plunker illustrating my code: http://plnkr.co/edit/tVOLYm2mg5be2L6NpM6k?p=preview

$scope.addRow = function() {
    $scope.accounts.unshift({ name: 'Enter Name', id: 'Enter ID', code: 'Enter Code'});
    //$scope.editable = true;
}

Can anyone assist with what I'm trying to accomplish?

thanks

1 Answer 1

1
$scope.editable = false;

This statement sets the editable value in the parent scope and ng-repeat makes child scope for every repeat. You need to understand that concept. Look at this question to understand that.

Now, a better way to implement what you want to do is by adding a new property to every account object in your accounts array that makes a row editable or non editable.

So whenever unshifting an account, do as follows:

 $scope.accounts.unshift({
      name: 'Enter Name',
      id: 'Enter ID',
      code: 'Enter Code',
      editable: true
  });

and in html, instead of using editable, use account.editable

You don't need to add editable property to your existing data as non-existent properties are implicitly falsy, so your grid will automatically be in non-editable mode initially.

Sign up to request clarification or add additional context in comments.

2 Comments

I see what you mean. I had tried adding that same code to my data and unshift script, but I didn't have it correct on html side, so wasn't working either. Much appreciation @Pranav Jindal!
Also, read the question and explanation to the question that I've hyperlinked. It'll really make you understand what's happening.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.