我在<input>
中有多个<form>
个字段。 Angular从这些字段中获取值,而不管<form>
(实际上只有Bootstrap才能将正确的样式应用于内部字段)。
现在,我希望能够重置字段,因此也可以让Angular更新与它们关联的输出。但是,常规<input type="reset"/>
按钮无效。它会重置所有<input>
字段的值,但Angular不会刷新基于其后的字段的输出。
有没有办法告诉Angular根据字段的当前状态刷新输出?类似于 ng-click="refresh()"
?
答案 0 :(得分:1)
假设您的模型名为address
。你有这个HTML表格。
<input [...] ng-model="address.name" />
<input [...] ng-model="address.street" />
<input [...] ng-model="address.postalCode" />
<input [...] ng-model="address.town" />
<input [...] ng-model="address.country" />
你在角度控制器中有这个。
$scope.reset = function() {
$scope.defaultAddress = {};
$scope.resetAddress = function() {
$scope.address = angular.copy($scope.defaultAddress);
}
};
JSFiddle可用here。
答案 1 :(得分:0)
您应该将您的值与模型绑定。
<input ng-model="myvalue">
输出:{{myvalue}}
$scope.refresh = function(){
delete $scope.myvalue;
}
JSFiddle:http://jsfiddle.net/V2LAv/
另请在此处查看$pristine
的示例用法:
http://plnkr.co/edit/815Bml?p=preview