0

I have a very simple app:

app = angular.module("GetTravelTime", ["ngResource"])


app.config ($routeProvider) ->
  $routeProvider.when("/",
    {
      templateUrl: "assets/pages/partials/home_controls.html"
      controller: HomeCtrl
    }
  )

@HomeCtrl = ($scope) ->
  $scope.data = {
    address: ""
  }

  $scope.change = (event) ->
    console.log $scope.data.address

home_controls.html

<section class="controls" ng-controller="HomeCtrl">
<input type="text" placeholder="Location name or Post Code" ng-model="data.address" ng-change="change()"/>
</section>

What I am trying to do is when the input field is changed I want to trigger an event but only when the user has finished typing. At the moment each keystroke triggers the change event. I would like it so when they have finished typing it then triggers the event.

In jquery I would do something like click out of the box. Is there a neat way to do this in angular?

Charlie Davies
  • 1,814
  • 4
  • 29
  • 50
  • 1
    See if this does what you want: http://stackoverflow.com/a/11870341/215945. Otherwise you can define a `blur` directive -- just search for `[angularjs] blur` on SO. – Mark Rajcok Mar 06 '13 at 21:29
  • You could also set a timeout (using the [`$timeout`](http://docs.angularjs.org/api/ng.$timeout) service) to only trigger the event after the user has paused for a certain length of time. Depends on your use case. – Josh David Miller Mar 07 '13 at 05:10
  • thanks guys I will investigate and report back – Charlie Davies Mar 07 '13 at 09:12
  • it does seem like a lot of code for a simple thing, i wonder if we can simplify it – Charlie Davies Mar 07 '13 at 09:15
  • possible duplicate of [Angularjs: input\[text\] ngChange fires while the value is changing](http://stackoverflow.com/questions/11868393/angularjs-inputtext-ngchange-fires-while-the-value-is-changing) – Benny Bottema Sep 18 '14 at 09:10

0 Answers0