1

我有一个页面,其中基于ng-repeat. 一切正常,直到将某些内容写入输入并且所有其他重复表单输入元素上的所有内容都被复制。我使用ng-model="Notify.message"的只是对象,它从输入中获取值并发送到按钮提交的控制,因此其余的逻辑。

我正在寻找如果一个表格被填写,其他表格应该保持不变并且不应该重复表格1的输入文本中写入的值。

这是代码:

<div data-ng-show="alluserposts.length > 0">
    <div id="b{{userpost.id}}" data-ng-repeat="userpost in alluserposts" >
            <div class="row" style="margin-left: -5px">
                <form class="text-center" role="form" id=f1{{userpost.id}} name="userForm"
                      ng-submit="notify(userForm.$valid, userpost, apiMe)" novalidate>
                    <div class="row">
                        <div class="col-xs-8 col-md-4">
                            <div class="form-group">
                                <input data-container="body" data-toggle="popover" data-placement="top"
                                       data-content="Any message which you would like to convey to post owner"
                                       type="text" ng-model="Notify.message" data-ng-init="Notify.message=''"
                                       id="u{{userpost.id}}"
                                       placeholder="Enter a Message or Phone number" class="form-control"
                                       required>

                                <p ng-show="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">It is
                                    required.</p>
                                <script>$(function () {
                                    $("[data-toggle='popover']").popover();
                                });
                                </script>

                                <input type="hidden" ng-model="Notify.loggedInEmail"
                                       ng-init="Notify.loggedInEmail = result.email"/>
                                <input type="hidden" ng-model="Notify.postId" ng-init="Notify.postId = userpost.id"/>
                                <input type="hidden" ng-model="Notify.destEmail"
                                       ng-init="Notify.destEmail = userpost.userEmail"/>
                            </div>
                        </div>

                        <div ng-show="loginStatus.status == 'connected'" class="col-xs-4 col-md-2">
                            <button class="btn btn-primary" ng-disabled="userForm.$invalid || !userForm.$dirty"
                                    type="submit">
                                Notify Post Owner
                            </button>
                        </div>
                    </div>
                </form>
                </p>
            </div>
        </div>
    </div>
</div>

问题小提琴 - jsfiddle

在这里,您可以在一个输入中写入某些内容时,其他内容也会被填充:(。此外,Notify 是一个 Java 映射对象,而 message 是其中的一个变量。请让我知道如何将其隔离!

4

2 回答 2

1

您将所有输入绑定到$scope. 您必须将每个文本框绑定到上的不同变量$scope

看法:

<ul ng-repeat="post in posts">
    <li>{{$index}}
        <input type="text" ng-model="emails[$index]"/>
    </li>
</ul>

控制器:

$scope.emails = [];
于 2014-05-11T06:57:51.740 回答
0

我也处于起步阶段angularjs

几天前我遇到了同样的问题,并通过提供动态模型名称来解决ng-model

<input type="text" ng-model="Notify[post.userEmail]" ng-init="Notify[post.userEmail] = post.userEmail" />

工作小提琴:Fiddle

于 2014-05-11T07:22:17.907 回答