0

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 AND 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 Answer 1

1

Change

From

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

To

ng-click="myFunction(question.id)"
Sign up to request clarification or add additional context in comments.

1 Comment

This is not working.actually the i am trying to call a division on click of that button using angularjs and i dont know how to do it.So finally its not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.