0

Any ideas how when the user selects the jquery select function, the code can execute the selectResults() (angular function) and pass in the user selected value?

minLength: 2,
delay: 500,
select: function (event, ui) {
    $('#fwSearch').val(ui.item.selectedValue);

    debugger;
    //navigate to the FirewallDetail page.
    selectResults($('#selectedUnit').val(ui.item.selectedValue));
}
1
  • 2
    I think your approach is wrong, angular does not expose any scope's methods to global, never. The thing you want to use is directives, yet I suggest you to follow the tutorial before everything docs.angularjs.org/tutorial Commented Sep 11, 2012 at 15:10

1 Answer 1

2

Here is how you can do it by using directive. http://plnkr.co/edit/ZFj4rz

In this example, it uses source and onselect attributes for handling autocomplete source and select event.

app.directive('autocomplete', function() {
  return { 
    restrict: 'A',
    scope: {
      source: '=',
      onselect: '='
    },
    link: function( scope, elem, attrs ) {
      $(elem).autocomplete({
        source: scope.source,
        delay: 500,
        minLength: 2,
        select: function( event, ui ) {
          scope.onselect( ui.item.value );
        }
      });
     }
  };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.