1

に基づいて複数のフォームが作成されるページがありますng-repeat。入力に何かを書き込むまで、すべてが正常に機能し、すべてが他のすべての繰り返しフォーム入力要素に複製されます。これはng-model="Notify.message"、入力から値を取得し、ボタンの送信時にコントロールに送信するオブジェクトにすぎないため、残りのロジックを使用しました。

1つのフォームが入力された場合、他のフォームは完全に保持され、フォーム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

ここでは、1 つの入力に何かが書き込まれると、他の入力も満たされます :( 。また、Notify は Java でマップされたオブジェクトであり、メッセージはその中の変数です。これをどのように分離できるか教えてください!

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 に答える