Tuesday, 23 June 2015

angular input timeout


With this you don't have to do a timeout.

ng-model-options="{debounce-=1000}"


<input ng-model="xxx " ng-model-options="{debounce-=1000}">


https://docs.angularjs.org/api/ng/directive/ngModelOptions




$rollbackViewValue() is the function you can use it to manually cancel the change and rollback.

<body ng-app="optionsExample">
  <div ng-controller="ExampleController">
  <form name="userForm">
    <label>Name:
      <input type="text" name="userName"
             ng-model="user.name"
             ng-model-options="{ debounce: 1000 }" />
    </label>
    <button ng-click="userForm.userName.$rollbackViewValue()">Clear</button>
    <br />
  </form>
  <pre>user.name = <span ng-bind="user.name"></span></pre>
</div>
</body>
</html>

This page has some animation pictures show and explain it:
https://docs.angularjs.org/guide/forms



No comments:

Post a comment