TypeError: Cannot read property 'push' of undefined, JavaScript

前端 未结 2 1314
野的像风
野的像风 2021-01-12 10:24

I\'m working in this Angular project where user submits a comment form, and the new comment is added to the comments that\'s already posted. Here is my code.



        
2条回答
  •  执念已碎
    2021-01-12 10:56

    You may try this

    .controller('productCtrl', function($scope, $http, $routeParams, Page){
      $scope.product = {};
      $scope.review = {};
      $scope.comments = [];
    
      routeparm = $routeParams.param;
    
      $scope.review = function(){
      var review_box = $scope.review_form.review_box;
    
    $http.post('./comment.php', {
        comment : review_box,
        code: routeparm
    }).success(function(data){
            $scope.comments.push(data.comments);
            $scope.review.review_box = '';
    }).error(function(data){
        $scope.has_error = true;
        $scope.error_message = data;
    })
    
    };
    

提交回复
热议问题