gpt4 book ai didi

angularjs - Angular js中的重置按钮

转载 作者:行者123 更新时间:2023-12-04 03:43:55 25 4
gpt4 key购买 nike

我有一个“清除”按钮,一旦用户点击容器中的所有数据,所有绑定(bind)和单选按钮都应该重置(就像最初一样)。目前只有 View 变为空,但容器仍然具有旧值。我该如何解决?

<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>

最佳答案

设置 ng-click对于某些功能,例如 reset()

<button class="btn btn-primary btn-large center" 
type="reset"
ng-click="reset()">Clear
</button>

然后将模型设置为空对象
$scope.reset = function() {
$scope.list = {};
}

或者,如果预先填充了 $scope.list,您可以执行以下操作(取自 Angular 文档):
function Controller($scope) {
$scope.master = {};

$scope.reset = function() {
$scope.list = angular.copy($scope.master);
};

$scope.reset();
}

关于angularjs - Angular js中的重置按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22459914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com