Angularjs 如何使用按钮清除具有相同ng模型输入的表单?
我有一个表单,它根据我之前选择的内容放置输入字段,这样我可以在表单中有不同数量的输入。我试过这样的方法:Angularjs 如何使用按钮清除具有相同ng模型输入的表单?,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我有一个表单,它根据我之前选择的内容放置输入字段,这样我可以在表单中有不同数量的输入。我试过这样的方法: $scope.person = { firstName: "John", lastName: "Doe" }; var oriPerson = angular.copy($scope.person); $scope.resetForm = function () { $scope.person = angular.copy(ori
$scope.person = {
firstName: "John",
lastName: "Doe"
};
var oriPerson = angular.copy($scope.person);
$scope.resetForm = function ()
{
$scope.person = angular.copy(oriPerson);
$scope.personForm.$setPristine();
};
但问题是,我可以使用相同的ng模型进行输入,因此,例如,当我尝试使用ng model=integer在输入中写入blabla时,它会自动将blabla放入使用ng model=integer的其他输入中。帮忙
感谢您将多个控件绑定到同一个属性,ng模型将控件绑定到一个属性,在您的情况下,属性是整数。如果希望它的行为有所不同,则需要不同的属性。i、 e.整数,酷整数,哑巴整数,超整数。。。发射型计算机断层扫描仪。那些可以有 如果要根据选择添加输入,则需要具有将ng模型命名为不同名称的逻辑,以便它们不绑定到相同的值。如果该值与人员关联,则可以根据范围内的人员命名,如:
ng-model="person.firstName"
然后,如果你有多个人,你可以复制你想要的,在你想要的地方
$scope.resetForm = function ()
{
$scope.person2 = $scope.person;
$scope.person = null;
// whatever else....
};
然后person.firstName的绑定输入被清除,您就有了副本。希望这会有所帮助。使用同名的multple模型不是一个好的做法:-p