2016-04-23 101 views

回答

2

重複:function called twice inside angularjs controller

這是您的audition.html

<div class="container-fluid fill" ng-controller="AuditionCtrl"> 
    <div class="row"> 
     <div class="col-lg-12 col-md-12 col-sm-12"> 
      <p>Welcome to exercise listening and typing!</p> 
      <br> 
      <button type="button" class="btn btn-default" ng-click="readbtn();">Play</button> 
      <br> 
      <input type="text" ng-model="userAnswer" placeholder="Type heard"> 
      <button type="button" class="btn btn-default" ng-click="nextWord();">Next word</button> 
      <button type="button" class="btn btn-default" ng-click="skipWord();">Skip</button> 
      <br> 
      <label id="labelMessage" ng-bind="showCorrect"></label> 
     </div> 
    </div> 
</div> 

這是你的應用程序的一部分.js

.when('/audition', { 
     templateUrl: 'partials/audition.html', 
     controller: 'AuditionCtrl', 
     access: { 
      requiredLogin: false 
     } 

正如答案中所述。您已將控制器連接到多個元素,從而導致控制器上的Angular調用摘要兩次。

+0

謝謝,非常簡單的解決方案! –