npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-bootstrap3-typeahead

v0.0.1

Published

Angular directive for bootstrap3-typeahead

Downloads

17

Readme

angular-bootstrap3-typeahead

AngularJS directive for the Bootstrap 3 Typeahead jQuery plugin.

##Usage

###Installation

$ bower install angular-bootstrap3-typeahead

or

$ npm install angular-bootstrap3-typeahead

###Registration

To be able to use the directive, you need to register the angular-bootstrap3-typeahead module as a dependency:

angular.module('yourModule', ['bootstrap3-typeahead'
 // other dependencies
]);

###Directive The directive maps declarative bs3-* attributes to their respective typeahead equivalences. The following example contains all of the supported attributes :

<input 
  type="text" 
  bs3-typeahead 
  ng-model = "$scope.variable"
  bs3-promise = "angular promise"

  bs3-source = "[]"
  bs3-items = "8"
  bs3-minLength = "1"
  bs3-showHintOnFocus = "false"
  bs3-scrollHeight = "0"
  bs3-displayText = "$scope.function"
  bs3-afterSelect = "$scope.function"
  bs3-addItem = "$scope.function"
  bs3-autoSelect = "true"
  bs3-delay = "0"
  bs3-matcher = "$scope.function"
  bs3-sorter = "$scope.function"
  bs3-updater = "$scope.function"
  bs3-highlighter = "$scope.function"
/>

For all the well known standard options I refer to the bootstrap3-typehead documentation. For the use of bs3-promise, a specialized option for bootstrap3-typeahead, se below.

###Example

Consider the following usage of bootstrap3-typeahead in an AngularJS app using AngularStrap (a better and more clean bootstrap implementation over the official Bootstrap UI)

var modal = $modal({
  scope: $scope,
  templateUrl: 'path/to/template',
  backdrop: 'static',
  show: true
})
modal.$promise.then(modal.show).then(function() {
  $('.typeahead').typeahead({
   showHintOnFocus: true,
   source: $scope.items,
   displayText: function(item) {
     return item.sagsNo
   },
   items: 15,
   afterSelect: function(item) {
     $timeout(function() {
       $scope.someId = item.id
     })
   }
  })
})

As you may see, there is several issues using this approach

  1. The need of "manually" initializing the typeahead
  2. We cannot use our $scope methods right away, for example along with afterSelect
  3. We must programmatically setup a wait condition, so the typeahead can be initialised when the modal is shown
  4. We must use a $timeout in order to be sure to update the $scope.someId variable
  5. It is in any aspect so far from "the angular way"

With the use of the bootstrap3-typeahead directive the same can be done as

markup:

<input bs3-typeahead bs3-source="items" bs3-displayText="displayText" bs3-afterSelect="afterSelect" />

script:

$scope.displayText = function(item) {
  return item.sagsNo
}
$scope.afterSelect = function(item) {
  $scope.someId = item.id
}

###Using bs3-promise

bs3-promise is a special attribute that let you assign a source with a delay. This can be useful if you need to use a source which origin from a service, a remote file or similar. It is a simple but effective attempt to angularish' the typeahead. Example :

$http.get('my-remote-file.json').then(function(response) {
	$scope.items = response
})
<input bs3-typeahead bs3-promise="items" />

bs3-promise does not actually use promises. If you specify bs3-promise then the directive will simply wait and $watch the referred $scope variable. Once the variable is set the typeahead is initialised. This also mean, that if you later on change the variable you are referring to in bs3-promise, then the typeahead will be reinitailised with the new variable as source. bs3-promise let you easily change source on the fly.