Guest User

Untitled

a guest
Oct 2nd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //HTML template:
  2. <input type="text" class="form-control" data-autocomplete="" data-source="/api/GetDestinations/" data-ng-model="destination" placeholder="Inserisci una destinazione..." value="" />
  3.  
  4. //directive:
  5. Shared.directive('autocomplete', function () {
  6.     return {
  7.         require: '^ngModel',
  8.         restrict: 'A',
  9.         scope: {
  10.             ngModel: '='
  11.         },
  12.         link: function (scope, elem, attr, ctrl) {
  13.             var options = {
  14.                 source: attr.source,
  15.                 minLength: 2,
  16.                 delay: 300,
  17.                 select: function (event, ui) {
  18.                     $(event.target).val(ui.item.label);
  19.                     scope.$apply(function () {
  20.                         scope.ngModel = { label: ui.item.label, value: ui.item.value };
  21.                     });
  22.                     return false;
  23.                 }
  24.                 , create: function (event, ui) {
  25.                     if (scope.ngModel)
  26.                         $(event.target).val(scope.ngModel.label);
  27.                     return false;
  28.                 }
  29.                 , focus: function (event, ui) {
  30.                     if (scope.destination)
  31.                         $(event.target).val(scope.ngModel.label);
  32.                     return false;
  33.                 }
  34.             };
  35.             elem.autocomplete(options);
  36.         }
  37.     };
  38. });
  39.  
  40. //main controller:
  41. function searchResultController($scope, $http, $routeParams, $location, suggerimentiData, suggerimentiDataService) {
  42.     destination={};
  43. };
  44. searchResultController.$inject = ['$scope', '$http', '$routeParams', '$location', 'suggerimentiData', 'suggerimentiDataService'];
Advertisement
Add Comment
Please, Sign In to add comment