0
TypeError: Cannot read property '{{ answer._id }}' of undefined
at Scope.$scope.showAddComment file : questions.client.controller.js:103:70)    

Here's my code:

<a class="btn btn-xs" data-ng-click="showAddComment('{{ answer._id }}');">
  Add Comment
</a><br />
<div class="col-md-12" ng-show="mustShow['{{ answer._id }}']">      
  <form class="form-horizontal" data-ng-submit="giveAnswerComment()" novalidate>
    <fieldset>
      <input type="hidden" data-ng-model="answer" id="answer" name="answer" value="{{answer._id}}">
      <div class="form-group">
        <div class="controls">
          <textarea data-ng-model="comment" id="comment" class="form-control" cols="30" rows="10" placeholder="Comment" required></textarea>
        </div>
      </div>
      <div class="form-group">
        <input type="submit" class="btn btn-default" value="Post Your Comment">
      </div>
      <div data-ng-show="error" class="text-danger">
        <strong data-ng-bind="error"></strong>
      </div>
    </fieldset>
  </form>
</div>



$scope.showAddComment = function(mustShowId) {
    console.log("Before mustShowId = " + mustShowId);
    // 103:70>
    console.log("Before $scope.mustShow[mustShowId] = "+$scope.mustShow[mustShowId]);
    $scope.mustShow[mustShowId] = true;
    console.log("After $scope.mustShow[mustShowId] = "+$scope.mustShow[mustShowId]);

};
1
  • Answer must not be defined on the scope where the template is being rendered. Can we see some more code, the code where answer is defined? Commented Jan 3, 2015 at 6:39

2 Answers 2

1
  1. You do not have $scope.mustShow = ... defined
  2. You do not need to use {{}} there. Just mustShow[answer._id]
  3. I think what you Are trying to do is simple ng-show="answer._id"
Sign up to request clarification or add additional context in comments.

Comments

1

Change your code to be as follows:

<a class="btn btn-xs" data-ng-click="showAddComment(answer._id);">
    Add Comment
</a><br />
<div class="col-md-12" ng-show="mustShow[answer._id]">      

Having the '{{ }}' made it not defined. Read about https://docs.angularjs.org/guide/expression AngularJS expressions

1 Comment

The error say that mustShow is undefined nit answer.

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.