황금같은 주말에 ㅅㅅ도 안하고 코딩중이다.


$scope.delete = function(post) {

      

      if ($scope.post.name) {

        var authAthor = $scope.isAuthor();

        authAthor.then(function() {

          post.$remove(function(response){

            angular.element('.modal-backdrop').remove();

            $location.path('/forum');

          }, function (errorResponse){ 

            $scope.error = errorResponse.data.message;

          });

        }, function() {

          alert('입력하신 비밀번호가 틀립니다.');

        });


      } else {

        post.$remove(function(response){

          $location.path('/forum');

        }, function (errorResponse){ 

          $scope.error = errorResponse.data.message;

        });

      } 

    };


    $scope.isAuthor = function() {

      var deferred = $q.defer();

      $http({

        method: 'POST',

        url: '/api/posts/auth/' + $scope.post._id,

        data: {

          _id : $scope.post._id,

          password : $scope.confirm_password

        }

      }).then(function successCallback(response) {

        deferred.resolve();

      }, function errorCallback(response) {

        deferred.reject();

      });


      return deferred.promise;

 

    };


고급 웹땔감이 되는 기분.