czmarc czmarc - 1 year ago 71
AngularJS Question

ng-click doesn't work with external JavaScript

I am creating an ionic project and I am trying to integrate with Algolia autocomplete.js. I managed to make the search system work, however I added a ng-click on my search results and this function is not working as presented in this codepen that I did as example below:

Inside my algolia's result template:

<a ng-click="add_name({{{ name }}})">

Function that should be run when clicked:

$scope.add_name = function(name) {
alert('User added!');

I tried to inject the results inside the scope but didn't work as well:

autocomplete('#search_name', { hint: false, debug: true, openOnFocus: true },[{
source: index.ttAdapter({ hitsPerPage: 15 }),
templates: {
header: '',
suggestion: function(hit) {

$scope.hit = hit;

return template.render(hit);


Answer Source


Here is the codepen:

Apparently the suggestion keep the name clicked, so you dont need an extra function:

.on('autocomplete:selected', function(event, suggestion, dataset) {

  $ =;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download