2017-02-16 69 views
0

我真的是javascript和angularjs的初學者,我陷入了某種工作,我不知道它是什麼出路。請有人幫我糾正我的錯誤角和javascript.Here是我的角度和HTML代碼page.Thanx提前在ng-click函數中傳遞參數不起作用

JavaScript和ANGULARJS PORTION

<script> 
    // Accordion 
    $scope.myFunction = function(id) { 
    //alert ("The id is"+id); 
    $scope.x = id; 
    if ($scope.x.className.indexOf("w3-show") == -1) { 
     $scope.x.className += " w3-show"; 
     $scope.x.previousElementSibling.className += " w3-theme-d1"; 
    } else { 
     $scope.x.className = $scope.x.className.replace("w3-show", ""); 
     $scope.x.previousElementSibling.className = 
     x.previousElementSibling.className.replace(" w3-theme-d1", ""); 
    } 
    } 
</script> 

<script> 
    var app = angular.module('myApp', []); 
    app.controller('myCtrl', function($scope, $http) { 
    alert("controller is getting called"); 
    $scope.loadquestions = function() { 

     alert("in the question section"); 

     $http({ 
      method: "POST", 
      url: "qpedia_php.php", 
      headers: { 
      'Content-Type': 'application/x-www-form-urlencoded' 
      } 
     }).then(function(response) { 


      alert("The question response is" + response.data); 
      $scope.questions = response.data; 


     }); 

     }, 



    }); 
</script> 

HTML PORTION

<div class="w3-row w3-accordion"> 
    <?php ?> 
    <button type="button" style="margin-right:75%;margin-left:8.33333%;" ng-click="myFunction('Demsl{{question.id}}')" class="w3-btn w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i>ANSWERS({{question.noofanswers}})</button> 
    <div id="Demsl{{question.id}}" class="w3-accordion-content w3-padding" ng-init="loadanswers();"> 
    <div class="w3-row"> 

     <div class="w3-col s10" style="margin-right:8.33333%;"> 
     <form method="post"> 

      <input type="hidden" name="q_user_id" value="<?php //echo $userid?>"> 
      <input type="hidden" name="q_id" value="{{answer.qid}}"> 

      <input class="w3-input w3-border" type="text" name="answer" placeholder="GIVE YOUR ANSWER HERE"> 
      <input type="submit" name="post_answer" value="" id="inputSuccess4" style="display:none;"> 
     </form> 
     </div> 
    </div> 

    <div class="w3-row-padding w3-card-4" style="margin:16px;" ng-repeat="answer in answers"> 
     <div class="w3-row" style="word-wrap:break-word"> 
     <div class="w3-col s2 w3-padding-large"> 

      <img src="{{answer.userpic1}}" class="w3-circle w3-margin-right" style="height:45px;width:45px" alt="Avatar"><span class="w3-text-white"></span></a> 


     </div> 
     <div class="w3-col s4" style=""> 
      <h4><b>{{answer.answername}}</h4></b> 

     </div> 

     </div> 

     <div class="w3-row"> 
     <div class="w3-col s8" style="word-wrap:break-word;margin-left:16.66666%;margin-right:16.66666%;"> 
      {{answer.ans}} 
     </div> 
     </div> 
     </br> 
     <div class="w3-row w3-container"> 
     <div class="w3-col s2" style="margin-left:16.66666%;"> 

      <form method="post"> 
      <input type="hidden" name="q_id" value="{{answer.qid}}" style="width:100px;"> 
      <input type="hidden" name="answer_id" value="{{answer.answerid}}" style="width:100px;"> 


      <button type="submit" name="answerlike" class="w3-btn w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-o-up"></i>|{{answer.noofanswerlike}}</button> 
      </form> 



     </div> 

     <div class="w3-col s2"> 



      <form method="post"> 
      <input type="hidden" name="q_id" value="{{answer.qid}}" style="width:100px;"> 

      <input type="hidden" name="user_id" value="<?php //echo $userid;?>" style="width:100px;"> 
      <input type="hidden" name="answer_id" value="{{answer.answerid}}" style="width:100px;"> 
      <button type="submit" name="answernounlike" class="w3-btn w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-o-down"></i>|{{answer.noofanswerunlike}}</button> 
      </form> 

     </div> 
     </div> 
     <div class="w3-accordion w3-row"> 

     <button type="button" style="margin-right:75%;margin-left:18%;" ng-click="myFunction('Deoslanswer.answerid')" class="w3-btn w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i>REPLIES({{answer.noofreplies}})</button> 


     <div class="w3-accordion-content w3-padding" id="Deosl{{answer.answerid}}" ng-init="loadreplies()"> 
      <div class="w3-row"> 

      <div class="w3-col s10" style="margin-right:8.33333%;"> 
       <form method="post"> 

       <input type="hidden" name="q_user_id" value="<?php //echo $userid;?>"> 
       <input type="hidden" name="q_id" value="{{answer.qid}}"> 
       <input type="hidden" name="answer_id" value="{{answer.answerid}}"> 

       <input class="w3-input w3-border" type="text" name="reply" placeholder="GIVE YOUR REPLY HERE"> 
       <input type="submit" name="post_reply" value="" id="inputSuccess4" style="display:none;"> 
       </form> 
      </div> 
      </div> 

      <div class="w3-row-padding w3-card-8" style="margin:16px;" ng-repeat="reply in replies"> 
      <div class="w3-row"> 
       <div class="w3-col s2"> 

       <img src="{{reply.userpic}}" class="w3-circle w3-margin-right" style="height:45px;width:45px" alt="Avatar"><span class="w3-text-white"></span></a> 



       </div> 
       <div class="w3-col s4"> 
       <h5><b>{{reply.answerreplyname}}</b></h5> 
       </div> 


      </div> 
      <div class="w3-row"> 
       <div class="w3-col s8" style="word-wrap:break-word;margin-right:16.66666%;margin-left:16.66666%;"> 
       <p>{{reply.answerreply}}</p> 
       </div> 
      </div> 

      </div> 

     </div> 
     </div> 
    </div> 

    </div> 
</div> 

回答

1

更改

ng-click="myFunction('Demsl{{question.id}}')" 

ng-click="myFunction(question.id)" 
+0

這不是working.actually的我試圖用angularjs調用該按鈕的點擊一個部門,我不知道該怎麼做所以最後它不工作。 –