likeastore / ngDialog

Modals and popups provider for Angular.js applications
http://likeastore.github.io/ngDialog
3.14k stars 692 forks source link

.push for reload data not working #481

Open nicogaldo opened 8 years ago

nicogaldo commented 8 years ago

I'm trying to send a comment and is displayed instantly on the modal window. I used this logic for send data from ng-repeat to modal.

Also, when I open the modal inside there is a ng-repeat with the comments of the post. When I try to post a new comment is not displayed instantly in the queue for comment.

$scope.guardarComentario = function(comment) {

    userdata = JSON.parse(window.localStorage.getItem('userdata'));
    $scope.comment = {};
    $scope.comment.text = comment.text;
    $scope.comment.idusuario = userdata.id;
    $scope.comment.id_noticia = $scope.noticia.id;
    $scope.comment.username = userdata.username;

    $http.post('urlapifornewcomment', $scope.comment).then(function(resp) {
        console.log(resp.data);
        $scope.comment = [];
        $scope.addComment = function() {
            $scope.comment.push(resp.data); //this not worknig.
        }

    }, function(err) {
        console.error('ERR', err);
        // err.status will contain the status code
    });
}

The form into ngDialog

<form ng-submit="guardarComentario(comment)">    
    <input type="text" class="form-control input-sm" ng-model="comment.text">
    <button type="submit" ng-click="addComment()">Enviar comentario</button>
</form>

You need to reload the page for comments is updated, and that is very bad for the practice of user. Any ideas?