Unique Ng-Model for a textArea in Ng-Repeat

494 views
Skip to first unread message

usermod2

unread,
Mar 10, 2016, 8:21:27 AM3/10/16
to AngularJS
Hi,

I'm going mad over this issue. Read (and tried) all sorts of suggestions from StackOverflow this Google group to no avail:

So i have a text area within a ng-repeat. I want to use that text area with ng-model however as it is repeating I want each text area to have a unique ID.

<div ng-repeat="options in optionsArray">
    {{options}}

<textarea rows="2" ng-model="detail.textArea[[$options]]"
   
placeholder="Enter your note here">
</textarea>

In addition to the above - have tried ng-model="detail.textArea[[$index]] however when i see the $scope I cant see that textArea.

I've also tried updating optionsArray so that instead of looking like:
[classa, classb, classc]

tried to use: 

[{name: classa, textAreaID: classaTextArea}, {name: classb, textAreaID: classbTextArea}, {name: classc, textAreaID: classcTextArea}]

However the issue with that was the actual textArea gets the text e.g. classaTextArea

Any ideas on what i need to do?

Thanks.

Sander Elias

unread,
Mar 10, 2016, 8:40:04 AM3/10/16
to AngularJS
Hi usermod2,

Why the complexity? Here is a small plunk to show you how a possible solution can work. If this is not what you need, alter the plunk, so I can see what it is you are aiming for.

Regards
Sander

usermod2

unread,
Mar 10, 2016, 8:48:04 AM3/10/16
to AngularJS
Thanks - I think i got it.

So what i'll do is in my current 'optionsArray' i'll update it so it contains an id and text variable.

Is this essentially what you suggest?

Regards.

Sander Elias

unread,
Mar 10, 2016, 8:55:42 AM3/10/16
to AngularJS
Hi usermod2,

Not exactly, but it will still work. That was the simplest data array I could come up with :) But yes, put the text's you want to edit in your optionsArray, and you are basicly done.

Regards
Sander

usermod2

unread,
Mar 10, 2016, 9:53:37 AM3/10/16
to AngularJS
Perfect - it worked!!
Reply all
Reply to author
Forward
0 new messages