[英]Input won't clear after form submission in AngularJS using Ionic framework
I have this weird problem. 我有这个奇怪的问题。 When I clear the model in the controller, the input field binded to the model with ng-model wont clear when the form is submitted.
当我在控制器中清除模型时,与ng-model绑定到模型的输入字段在提交表单时不会清除。
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 = "";
};
}]);
Template 模板
<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>
I get the console output "I get there", so the function gets activated. 我得到了控制台输出“我到那里”,因此该功能被激活。 What am I missing here?
我在这里想念什么?
clearInput()
and ng-model
refer to different scopes after the value of input has changed. 输入值更改后,
clearInput()
和ng-model
引用不同的作用域。 Please see this SO answer for deeper explanation. 请参阅此SO答案以获得更深入的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.