angular text input adds values to repeated text inputs

By : Atma
Source: Stackoverflow.com
Question!

I have a series of comment inputs that repeat. When I start typing in one, all inputs are populated with the characters I am typing.

How do I have the text input value only populate in the text input I am typing into?

Here is what my template looks like:

<li ng-repeat="post in feed.posts" class="media media-clearfix-xs">
<form ng-submit="feed.addComment(post.id, post.comment_set)">
  <div class="input-group">
    <input ng-model="feed.desc" type="text" class="form-control" />
        <span class="input-group-btn">
         <button ng-click="submit()" class="btn btn-default"><i class="fa fa-comment-o"></i></button>
        </span>
</div>
</form> 
</li>
By : Atma


Answers

It should not , since you have a array where each object which deals with each line, change ng-model to be post.desc not feed.desc

<input ng-model="post.desc" type="text" class="form-control" />

DEMO



You should have that desc property on post level instead of directly putting inside controller context feed(assuming feed is controller alias)

<input ng-model="post.desc" type="text" class="form-control" />


$(this) is refering to the Window object and thus not what you expect to be. You can pass "this" to the function inside the inline JS call, and create a jQuery element of the argument. See the snippet:

function showImage(element, imageSrc) {

            $('a.slideTabLinkBlock').removeClass('active');
            alert($(element).attr('class'));
            $(element).addClass('active');

        }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="slideTabLinkBlock" onclick="showImage(this, '<?php echo $image_src; ?>');">Link</a>



This video can help you solving your question :)
By: admin