Sar*_*ara 9 radiobuttonlist radio-button angularjs
我有一个"清除"按钮,一旦用户点击容器中的所有数据,所有绑定和单选按钮都应该被重置(就像最初一样).目前只有视图变空,但容器仍然是旧值.我该如何解决?
<div class="field">
<textarea name="price" ng-model="list.price"></textarea>
</div>
<input type="radio" ng-model="list.phone" value="1" />cell
<input type="radio" ng-model="list.phone" value="2" />home
<button class="btn btn-primary btn-large center" type="reset" ng-click="">
Clear
</button>
Run Code Online (Sandbox Code Playgroud)
Tom*_*Tom 11
ng-click
比如设置一些功能reset()
<button class="btn btn-primary btn-large center"
type="reset"
ng-click="reset()">Clear
</button>
Run Code Online (Sandbox Code Playgroud)
然后将模型设置为空对象
$scope.reset = function() {
$scope.list = {};
}
Run Code Online (Sandbox Code Playgroud)
或者,如果$ scope.list已预先填充,您可以执行以下操作(取自angular docs):
function Controller($scope) {
$scope.master = {};
$scope.reset = function() {
$scope.list = angular.copy($scope.master);
};
$scope.reset();
}
Run Code Online (Sandbox Code Playgroud)