Created
May 18, 2015 15:50
-
-
Save benoror/178efc3fd185352095f7 to your computer and use it in GitHub Desktop.
angular-formly select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ui-select ng-model="model[options.key]" theme="bootstrap" reset-search-input="false"> | |
<ui-select-match>{{$select.selected[to.labelProp || 'name']}}</ui-select-match> | |
<ui-select-choices repeat="option in to.options | filter: $select.search"> | |
<div ng-bind-html="option[to.labelProp || 'name'] | highlight: $select.search"></div> | |
</ui-select-choices> | |
</ui-select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select class="form-control" | |
ng-model="model[options.key]" | |
ng-options="option[to.valueProp || 'value'] as option[to.labelProp || 'name'] group by option[to.groupProp || 'group'] for option in to.options"> | |
</select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Custom Templates for angular-formly | |
*/ | |
angular.module('myapp') | |
.config(function config(formlyConfigProvider) { | |
/** | |
* Custom templates | |
* http://docs.angular-formly.com/v6.4.0/docs/custom-templates | |
*/ | |
/* | |
select | |
*/ | |
formlyConfigProvider.setType({ | |
name: 'select', | |
overwriteOk: true, | |
templateUrl: 'scripts/formly/select.html', | |
wrapper: ['bootstrapLabel', 'bootstrapHasError'] | |
}); | |
/* | |
async_select | |
Extends select | |
use ui-select (https://github.com/angular-ui/ui-select) | |
*/ | |
formlyConfigProvider.setType({ | |
name: 'async_select', | |
extends: 'select', | |
templateUrl: 'scripts/formly/async_select.html', | |
defaultOptions: { | |
templateOptions: { | |
options: [], | |
valueProp: "value", | |
labelProp: "label", | |
}, | |
controller: function($scope, CRUDService) { | |
$scope.to.loading = CRUDService.options($scope.to.params).then(function(res) { | |
$scope.to.options = res; | |
// note, the line above is shorthand for: | |
// $scope.options.templateOptions.options = data; | |
return res; | |
}); | |
} | |
// Alternative: Use ui-select's `refresh` functionality | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment