Search code examples
angularjsangular-ngmodel

Target a specific element in ng-repeat AngularJS


right now I am working on an AngularJS project with some C# for back-end. What I would like to do.. I have a ng-repeat, and in that I have a text-area. I need the text form them but in different models cuz I want to insert them into my database. Here Is my code

    <div ng-controller="answerController as vm">
    <div class="container-fluid" ng-repeat="obj in vm.User">
        <div class="row">
            <div class="col-md-3">
                <h3>Question</h3>
                <h2>{{obj.question}}</h2>
            </div>
            <div class="col-md-3">
                <h3>Correct answer</h3>
                <h2>{{obj.answer}}</h2>
            </div>
            <div class="col-md-3">
                <h3>Candidate's answer</h3>
                <h4>Answered in:  <strong>{{obj.userTime}}</strong></h4>
                <h2>{{obj.userAnswer}}</h2>

            </div>
            <div class="col-md-3">
                <h3>Your feedback</h3>
                <textarea name="" placeholder="Your feedback..." id="" cols="60" rows="8" ng-model="vm.feedback"></textarea>
            </div>
        </div>
        <hr>
    </div>

    <button class="btn btn-success" ng-click="vm.submit()">Submit feedback</button>
</div>

it makes me 4 text-area and I need the text of each and if I put ng-model will not work. Any help would be awesome. thank you


Solution

  • I resolved it, instead of

    vm.feedback

    you have to use

    vm.feedback[$index]

    so vm.feedback[0] will be your first text area and so one..