简体   繁体   English

在ng-click函数中传递参数不起作用

[英]Passing parameter in ng-click function not working

I am really beginner in javascript and angularjs and i am stuck into some kind of work and i dont know what is the way out of it.Please somebody help me to correct my mistake in angular and javascript.Here is my code for angular and html page.Thanx in advance 我真的是javascript和angularjs的初学者,我陷入某种工作中,我不知道它的出路是什么。请有人帮我纠正我在angular和javascript中的错误。这是我的angular和html代码page.Thanx提前

JAVASCRIPT AND ANGULARJS PORTION JAVASCRIPT和ANGULARJS部分

<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 HTML部分

<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>

Change 更改

From

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

To

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM