1

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?

Felix D.
  • 2,180
  • 1
  • 23
  • 37

1 Answers1

1

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

Community
  • 1
  • 1
Kate Miháliková
  • 2,035
  • 15
  • 21