5

I currently use AngularJS and Bootstrap. I want to make a typeahead which show all options when he is selected (when I click on it) not only when I wrote somthing on it. like the example on this site which use JQuery (I can't use JQuery).

here is my controller

countrycatControllers.controller('CountryListCtrl',['$scope',
    function ($scope) {
        $scope.listCountry = [
        {"name": "Switzerland"},
        {"name": "France"},
        {"name": "Spain"},
        {"name": "Brazil"},
        {"name": "Argentina"},
        {"name": "USA"},
        {"name": "Canada"},
        {"name": "China"},
        {"name": "Germany"},
        {"name": "Italy"}
        ];
    }
])

and here is my HTML input :

<pre>Model: {{country | json}}</pre>
<input data-ng-model="country" typeahead="item.name for item in listCountry | filter:$viewValue"/>
0

2 Answers 2

3

There is an 100% angular directive for the Select2 plugin.

Check out https://github.com/angular-ui/ui-select

Sign up to request clarification or add additional context in comments.

Comments

0

You can do that on your own by using filter:

<div ng-app>
    <div ng-controller="CountryListCtrl">
        <div>
            <input type="text" placeholder="Enter country here" ng-model="search.name" size="80" ng-focus="modeExpanded=true" ng-blur="modeExpanded=false" />
            <div ng-show="modeExpanded">
                <div ng-repeat="item in listCountry | filter:search">{{item.name}}</div>
            </div>
        </div>
    </div>
</div>

See http://docs.angularjs.org/api/ng/filter/filter. The idea is that the search model mimics the structure of the listCountry entries. ng-focus and ng-blur are used to get show the list only when you actually click on the input element.

1 Comment

thanks for your idea but I'm trying to use a real typeahead like in my example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.