1

I have an ionic angular app that started to fire the ng-click twice in a row if I add an ng-disabled property (I wanted to prevent them from clicking the button twice).

Why does it fire twice in a row with that ng-disabled property?

<button ng-if="post._id" 
  class="button button-block button-outline" 
  ng-click="createPost()" 
  ng-disabled="isSaving">Update</button>
||||||
  • 1
    where does isSaving come from? – Callum Linington Jan 22 '15 at 13:43
  • I think I know what you are doing, and I have a neat solution for this. What I do is switch the contents of the button with a spinner, and then in the method just say if (isSaving) return; – Callum Linington Jan 22 '15 at 13:46
  • works fine for me: plnkr.co/edit/NYLJuN5MyjtfFUv2uIzh – New Dev Jan 22 '15 at 14:02
  • does it work properly without ng-disabled? – Pankaj Parkar Jan 22 '15 at 14:24
  • try to write type="button" because by default it is "submit".possibilty is that when you hit button it is submitting form directly – Pankaj Parkar Jan 22 '15 at 14:46
-1

I haven't got an answer for your problem, but I have another solution for your problem, here is a plnkr

I made a directive called networkInfo which sets the buttons content depending on whether the network call is being made or not.

It's not the perfect way, but a link function in 7 lines, and a button with two attributes on it ain't half bad.

The attribute makingCall is just a boolean of whether the call is being made. The attribute networkInfo initiates the directive and fires the link function binding makingCall to its scope.

The function update() uses $timeout to imitate an asynchronous network call (using $http or something).

Firstly it checks vm.working, if it is true then don't make another network call. Then it sets it to true, to inform the directive that a call is now in process.

Finally it fires the $timeout which after 2secs will set vm.working back to false to indicate the end of the network call.

Obviously I have used boostrap because that is what i'm more familiar with, however, like iconic its just stylings.

||||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.