By John O'Connor.
Colour selected: {{selectedColour.name}}
<ac-select ac-model="selectedColour" ac-options="c.name for c in colours"
ac-change="colourChanged(value)"></ac-select>
$scope.selectedColour = $scope.colours[2]; // red.
$scope.colourChanged = function (value) {
var colourName = value ? value.name : "none";
$scope.message = "ac-change event fired for colour. New colour: " + colourName;
$scope.$digest();
};
$scope.colours = [
{ name: 'black', id: 0 },
{ name: 'white', id: 1 },
{ name: 'red', id: 2 },
...
State selected: {{stateInfo}}
<select class="ac-select stateList" ac-model="selectedState" ac-options="s.name for s in getAllStates()"
ac-settings="{ loadOnOpen: true, minWidth: '300px' }" ac-change="stateSelected(value)"></select>
Here, the parentheses on "getAllStates()" tell the ac-select directive to call a function to get the data for the dropdown.
Note that the ac-change function must be specified with a parameter called "value".
$scope.getAllStates = function (callback) {
callback($scope.allStates);
};
$scope.stateSelected = function (state) {
$scope.stateInfo = state.name + " (" + state.id + ")";
}
$scope.allStates = [
{ "name": "Alabama", "id": "AL" },
{ "name": "Alaska", "id": "AK" },
...
ac-select passes a callback function to accept the data, so it can be read asynchronously if required.
I.e. a combined text box and dropdown.
State selected: {{stateInfo}}
<select class="ac-select stateList" ac-model="selectedState" ac-options="s.name for s in getAllStates()"
ac-settings="{ comboMode: true, loadOnOpen: true, minWidth: '300px' }" ac-change="stateSelected(value)"></select>
Combo mode is enabled by including "comboMode: true" in the ac-settings attribute.
$scope.getAllStates = function (callback) {
callback($scope.allStates);
};
$scope.stateSelected = function (state) {
$scope.stateInfo = state.name + " (" + state.id + ")";
}
$scope.allStates = [
{ "name": "Alabama", "id": "AL" },
{ "name": "Alaska", "id": "AK" },
...
ac-select passes a callback function to accept the data, so it can be read asynchronously if required.
See github README for a full list of settings.