Felix D.
Felix D.

Reputation: 2220

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.

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?

Upvotes: 1

Views: 6184

Answers (1)

clearInput() and ng-model refer to different scopes after the value of input has changed. Please see this SO answer for deeper explanation.

Upvotes: 1

Related Questions