1

The issue is in chrome where I have few fields in a form and want to utilize autocomplete feature of the browser. Here I found the problem with chrome(that it save data only on form submit) and therefore as suggested by the accepted answer on this question, I tried to fire the click event which in turn fires the ngClick on the same element which eventually runs into a loop.

So how do I make use of autocomplete feature while still using "ngClick"?

Community
  • 1
  • 1
me_digvijay
  • 5,374
  • 9
  • 46
  • 83

2 Answers2

2

The cleanest way to trigger autocomplete would be to use ngSubmit. However as you want to use ngClick, a solution like this https://stackoverflow.com/a/25102791 would work. You are submitting the form from the controller. Triggering the native submit function needs to be applied through a directive as this is the recommended place to manipulate the DOM using AngularJS.

Community
  • 1
  • 1
emjrose
  • 112
  • 4
1

I was looking for this too and came across this post so I will share what I have discovered so far with my own solution, and hopefully it helps :) I also encountered an infinite loop with my autocomplete and after many trials I discovered if I call my function differently it doesn't push the loop.

on-select="ctrl.updateAutoComplete"

I believe that will still work for your ngClick (basically I just removed the brackets here)

and then in my controller instead of using

public updateAutocomplete(query: string) {//do stuff here}

I ended up using

public updateAutocomplete = function(query: string) { // do stuff here }

it seems like kind of a brutish way of getting around it but so far it's working for me. I found it also obscures the $scope a bit which is why I am looking for a better solution. But anyways this is how I got away from the loop, I hope it helps.

AaronH
  • 109
  • 6