gpt4 book ai didi

javascript - $scope 和 setPristine() 不在工厂内工作

转载 作者:行者123 更新时间:2023-11-28 18:34:19 25 4
gpt4 key购买 nike

我正在尝试将当前的 api 调用写入可在 ApiService 工厂内重用的工厂。但是,我似乎无法清除表格。

那么,我能做些什么来使clearForm函数按原样工作。

<form name="formName">
<input type="name" ng-model="form.username"></input>
<input type="password" ng=model="form.password"></input>
<button type="submit" ng-click="submitForm()">Submit</button>
<form>

最佳答案

表单位于$scope中。如果不使用 $scope 就无法访问它,并且工厂没有 $scope

尝试这样

$scope.formName.$setPristine();

您所能做的就是将该表单传递给服务并清除它

'clearForm': function(formName) {
formName.$setPristine();
formName.$setUntouched();
}

来自 Controller

FormFactory.clearForm($scope.formName);

关于javascript - $scope 和 setPristine() 不在工厂内工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37411354/

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