AngularJS ng-click fires twice

后端 未结 18 1791
死守一世寂寞
死守一世寂寞 2020-12-03 07:10

I am using ng-click and it fires twice when I apply it to SPAN tag.

HTML

18条回答
  •  Happy的楠姐
    2020-12-03 07:51

    I had a similar problem, but could not find where I included Angular twice in my files.

    I was using an ajax calls to load specific form layouts, so I need to use $compile to activate Angular on the inserted DOM. However, I was using $compile on my directive $element which has a controller attached. Turns out this "includes" the controller twice, causing two triggers with ng-click or ng-submit.

    I fixed this by using $compile directly on the inserted DOM instead of my directive $element.

提交回复
热议问题