我有一个奇怪的问题。当我清除 Controller 中的模型时,提交表单时,使用 ng-model 绑定(bind)到模型的输入字段将不会清除。
Controller
angular.module('starter.controllers', [])
.controller('DashCtrl', ["$scope", function($scope) {
$scope.clearInput = function() {
console.log("I get there...");
//Here's the issue!!! It's not working as expected!
$scope.message = "";
};
}]);
模板
<ion-view title="Dashboard">
<ion-content class="padding">
<form name="myform" ng-submit="clearInput()">
<label class="item item-input">
<input type="text" ng-model="message"/>
</label>
<button type="submit" class="button button-positive" >
button-positive
</button>
</form>
</ion-content>
</ion-view>
我得到控制台输出“我到达那里”,因此该功能被激活。我在这里缺少什么?
最佳答案
clearInput()
和 ng-model
在输入值更改后引用不同的范围。请参阅this SO answer以获得更深入的解释。
关于javascript - 使用 Ionic 框架在 AngularJS 中提交表单后输入不会清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27034797/