John Aims
John Aims

Reputation: 49

Binding multiple input models

I'm trying to bind a ng-model this way:

      <md-list-item ng-repeat="reply in replies">
        <md-input-container flex style="margin-top:-7px;" ng-show="replyLink">
          <label>Your reply ...</label>
          <input ng-model="replyMsg" ng-enter="addReply(reply.id)">
        </md-input-container>
      </md-list-item>

From the other side:

 $scope.replyMsg...

Using this, when I change the value of one ng-model and log the content of replyMsg, I get undefined as output message. How do I fix that?

I've tried to make it ng-model="replyMsg{{$index}}", but, I wasn't able to find out how to deal with this model name in the other side using $scope.

Any brilliant suggestion?

Upvotes: 1

Views: 364

Answers (2)

tarlepp
tarlepp

Reputation: 358

I made simple plunker of that hope this helps.

`http://plnkr.co/edit/OUqh5l1omH9Tgv6xAyBO?p=preview`

Upvotes: 0

ngLover
ngLover

Reputation: 4578

you can do it in this way . every reply will contain their reply msz.

<md-list-item ng-repeat="reply in replies">
        <md-input-container flex style="margin-top:-7px;" ng-show="replyLink">
          <label>Your reply ...</label>
          <input ng-model="reply.replyMsg" ng-enter="addReply(reply.id)">
        </md-input-container>
      </md-list-item>

Upvotes: 1

Related Questions