       search.bind 'input', ->
         buildTemplate()
       buildTemplate = ->
-        list= []
+        template.empty()
         obj={}
         obj[viewValue] = search.val() || ''
         return unless collection(scope)

        unless done = typeof fieldset[0] == 'undefined'
          done = fieldset[0].tagName == 'FIELDSET'
      element.parent('fieldset')
      element.bind 'mousedown', (event)->
        return if tempHolder.hasClass('active')
        return if attrs.disabled || $parse(attrs.ngDisabled)(scope)
        if fieldset
          ngdis = if fieldset[0].attributes.ngDisabled then fieldset[0].attributes.ngDisabled.value else ''
          return if fieldset[0].attributes.disabled || $parse(ngdis)(scope)
        search.val('')
        buildTemplate()
        tempHolder.css('top',event.clientY)
        tempHolder.css('transition','none')
        $timeout ->
          tempHolder.css('transition','')
          tempHolder.css('top','')
          tempHolder.addClass('active')

          [filterType,value] = filter.replace(/\s+/,'').split(':')
          filteredList = $filter(filterType)(filteredList, value)
        for item in filteredList
          if isMobile
            li = angular.element '<li>' + viewValueFn(item) + '</li>'
          else
            li = angular.element '<a class="item">' + viewValueFn(item) + '</a>'
          ip = angular.element '<input type="hidden">'
          ip.val(modelValueFn(item))
          li.append(ip)
          li.bind 'mousedown', ($event)->
            updateValue($event.target.children[0].value)
          template.append(li)
      setInitialValue = ->
        unless isMobile
          obj = {}
          obj[modelValue] = ngModel.$modelValue
          list = $filter('filter')(collection(scope), obj,true)
          viewScope = list[0] if list
          search.val(if viewScope then viewValueFn(viewScope) else '')
        else
          unless model = ngModel.$modelValue
            view = attrs.placeholder
            element.css('color','rgba(0,0,0,0.4)')
          else
            element.css('color','')
            obj = {}
            obj[modelValue] = model
            list = $filter('filter')(collection(scope), obj,true)
            viewScope = list[0] if list
            view = if viewScope then viewValueFn(viewScope) else attrs.placeholder
          element.html('')
          element.html(view)

      setInitialValue()
      buildTemplate()
      updateValue = (model) ->
        ngModel.$setViewValue(model)
        tempHolder.removeClass('active')
        $timeout ->
          setInitialValue() unless isMobile
      done = false
      fieldset = element
      until done
