我有一个基于ng-repeat创建多个表单的页面。一切工作正常,直到写入输入的东西,所有其他重复的形式输入元素重复所有。我已经使用ng-model =“Notify.message”,它只是一个对象,它从输入中获取值并发送到按钮提交的控件,因此也是逻辑的其余部分。ng-model和ng-repeat的问题,inout值在页面上的每个表单域上都是重复的
我找的时候,如果一个表单被填满,其他形式应保持安静,不应该重复的写在表格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>
既然你要绑定所有输入'NG-model'为'Notify.message',如果任何一个更新它的其它形式会得到它由于数据绑定?你应该有每个重复输入的独立模型,以使其独立工作 – Chandermani
@Chandermani - 我怎样才能有独立的模型?有没有办法为每个新表单重新初始化? – AngryJS
@Chandermani - ? – AngryJS