Search code examples
angularjsangular-uiangular-bootstrapangular-ui-typeahead

append to the typeahead list of suggestions


hi i'm really struggling with this and not sure how to proceed as I haven't found anything ont his. Here's the plunkr example I'm working with: example. I want to append something at the end of the results for example if I type S, I want to get the results and the last line should say "Look for S in other shops" :

Sauron
Bowser
Yoshi
Look for S in other shops

As you can see in my plunker, whatever I do in the template, ends up getting repeated.


Solution

  • Define your custom filter:

    .filter('finalAppend', function(){
      return function(array, value){ 
        array.push({
        name: 'Look for ' + value + ' in other shops',
        type: 'good'
      }); 
        return array;
      }
    });
    

    And use it like this:

    <input type="text" ng-model="selected" 
     typeahead="datum.name for datum in (data|filter:$viewValue|limitTo:8)|finalAppend:$viewValue" 
     typeahead-template-url='tpl.html'>
    

    Example