           val = ele.val()
           if val.length < minKeyCount
             if timer
-              .cancel timer
+              $timeout.cancel timer
             scope.reslist = null
             return
           else
             if timer
-              .cancel timer
-            timer = ((->
+              $timeout.cancel timer
+            timer = $timeout((->
               scope.autoFill()(val).then (data) ->
                 if data and data.length > 0
                   scope.reslist = data

  WeatherProvider.setApiKey '$API_KEY'
  return
).config([
  ''
  () ->
    .when('/',
      templateUrl: 'templates/home.html'
      controller: 'MainCtrl').when('/settings',
      templateUrl: 'templates/settings.html'
      controller: 'SettingsCtrl').otherwise redirectTo: '/'
    return
]).directive('autoFill', (, Weather) ->
  {
    restrict: 'EA'
    scope:

      @apiKey = key
    return

  @$get = ($q, $http) ->
    self = this
    {
      getWeatherForecast: (city) ->
        d = $q.defer()
        $http(
          method: 'GET'
          url: self.getUrl('forecast', city)
          cache: true).success((data) ->
          d.resolve data.forecast.simpleforecast
          return
        ).error (err) ->
