im体育网页版比分

Typeahead for AngularJS with Ajax

UI Bootstrap is a set of directives for AngujarJS with support for Bootstrap. Some of them are:

UI Bootstrap is a set of directives for AngujarJS with support for Bootstrap. Some of them are: Alert, Accordion, Buttons, Carousel, Collapse, Datepicker, Modal, Pagination, Popover, etc.

Typeahead is one among many directives for AngujarJS and it allows us to create typeaheads quickly with any text input. It also comes with support for Bootstrap 3.

In order to use it, we only have to reference the directive in the input:

												
											

To use AngularJS with Ajax , we have to specify the function of the controller in charge of bringing the data. In our case, it would be getStates() :

												
											

In the controller:

												$scope.getStates = function(state){ return $http.get('http://myservice.com/api/states', { params: { state: state } })
											

You can see that our function returns a $promise. This is a requirement for async calls. If you wish to handle sync calls, you could return an array directly.

As our function will eventually return an array of State objects, we will ask Angular to use the Name property for each item so they appear on the list.

This directive also allows us to specify extra filters on the list that will be shown later, such as showing only 8 items at most from the full results using:  limitTo:8

												
											

It is also possible for us to specify a wait time before executing the function we pass, using:

												typeahead-wait-ms="300"
											

Finally, we can specify a minimum number of characters before executing the function we pass, with:

												typeahead-wait-ms="300"
											

For further information about this directive and many more, visit the official UI Bootstrap web page.

Are you looking for the best technical solution for your company? Contact us  for more information and we will get back to you!