Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

javascript - $scope's method called via ng-click: executed twice by IE

In my controller:

$scope.homeAction = function() {
  console.log("HomeAction");
};

In my view:

<button ng-click="homeAction()">call homeAction()</button>

When clicking the button, the method gets executed as expected by Chrome and Firefox, but IE executes it twice. Any idea why?

Here is a plunker that reproduces the issue: http://plnkr.co/edit/pedZKjIVGDAYfMl0ZphJ.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just add type="button"to your button and it should be fixed. Default behaviour is submit and apparently that messes with your code.

<ion-view title="Home">

  <ion-content padding="true">
    <button type="button" ng-click="homeAction()" class="button button-block button-positive">call homeAction()</button>
  </ion-content>

</ion-view>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...