pagarme-ng-dropdown
Pagar.me directive to provide a simple and quick dropdown from a provided array of options
For angular versions < 1.3 that does not supports bindToController
, you should see this branch.
here
Check the demoInstallation
Install via npm package manager:
$ npm install pg-ng-dropdown
Import the directive file into your project:
If you wish the same style of the example, import the css.
Load the pg-ng-dropdown module:
angular.module('myApp', ['pg-ng-dropdown']);
Call the directive in an element via attribute, class or tag name:
Pass the data via attribute:
Give a model to the dropdown:
Array expected format
The options array must contains one JSON for each option.
Example:
var myOptionArray = text: 'Carl Sagan' image: 'img/carl.png' //if image-options is set to true value: 0 text: 'Stephen Hawking' image: 'img/stephen.png' //if image-options is set to true value: 1 text: 'Michio Kaku' image: 'img/michio.png' //if image-options is set to true value: 2 ;
Directive Optionals
You can choose what property from the json you wish to be used as value for the model, instead of the default value
.
On the given example below, the text of the option will be set to the model, instead of its value.
Also choose the object property to display the text of the option, instead of the default text
:
You can do the same to set the image url of the option, instead of the default image
:
Set the empty text that will be displayed when model is empty or does not matches any of the options:
Enable image options (default is false
):
Opened dropdown class (default is opened
):
Selected option class (default is selected
):
Option selected/changed custom function:
Dynamic Height support:
To simulate ng-disabled functionality, you must pass a function that return the disabled condition result:
$scope{ return $scopevalA !== $scopevalB; };
Registered Scope Events
You can communicate with each of the dropdowns in your page by naming them with the attribute name
:
And you can open and close a dropdown trough scope events by passing as data the name of the directive:
//opening$scope; //closing$scope;
You can also select a given option:
//select the third option$scope;
Accessibility
Supports tab index, with enter
, esc
, up
and down
arrows controls. Enter key opens the focused dropdown and esc closes it. Use up and down arrow to choose an option and press enter again to select it.
Testing
This directive has e2e testing specs done by protractor.
Follow protractor's instructions, run gulp server
task and run testing command protractor protractor.conf.js
to run the test cases.
And that's it :D