Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Select2 AngularJs directive example with custom query call to append data to the request. Note: Providing ajax settings is not needed (and not used) when query is provided. Left here as a full example.
# The "query" configuration is adapted from this gist: https://gist.github.com/techniq/4609063
.directive 'remoteSelectPlugin', ['$http', ($http) ->
{
restrict: 'A'
link: (scope, elem, attr) ->
angular.element(elem).select2({
placeholder: attr.remoteSelectPlugin
minimumInputLength: 1
query: (options) ->
$http.get "http://example.com"
.then (response) ->
options.callback({more:false, results: response.data})
formatResult: (judgment) ->
'<p>' + judgment.case_title2 + '</p>' + '<span class="label label-primary">' + judgment.suitno + '</span>' + '<span class="label label-success pull-right">' + judgment.date + '</span>'
formatSelection: (judgment) ->
"#{judgment.case_title2} - #{judgment.suitno}"
dropdownCssClass: "bigdrop"
})
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.