Javascript 使用PUT从列表中删除用户?在AngularJS

Javascript 使用PUT从列表中删除用户?在AngularJS,javascript,angularjs,put,Javascript,Angularjs,Put,我正在创建一个web应用程序。其中,我有一个后端api,我使用GET方法接收我的用户,在一个页面上有用户信息,其中有一个确认按钮。我想用确认按钮做的是,当我从PUT中获得200时,我想从列表中删除该用户。我试过了,但我需要一些帮助。提前谢谢 这是我的密码 App.js 指示 app.directive('confirmClick', ['$q', 'dialogModal', function($q, dialogModal) { return { link: funct

我正在创建一个web应用程序。其中,我有一个后端api,我使用GET方法接收我的用户,在一个页面上有用户信息,其中有一个确认按钮。我想用确认按钮做的是,当我从PUT中获得200时,我想从列表中删除该用户。我试过了,但我需要一些帮助。提前谢谢

这是我的密码

App.js

指示

app.directive('confirmClick', ['$q', 'dialogModal', function($q, dialogModal) {
    return {
        link: function (scope, element, attrs) {
            // ngClick won't wait for our modal confirmation window to resolve,
            // so we will grab the other values in the ngClick attribute, which
            // will continue after the modal resolves.
            // modify the confirmClick() action so we don't perform it again
            // looks for either confirmClick() or confirmClick('are you sure?')
            var ngClick = attrs.ngClick.replace('confirmClick()', 'true')
                .replace('confirmClick(', 'confirmClick(true,');

            // setup a confirmation action on the scope
            scope.confirmClick = function(msg) {
                // if the msg was set to true, then return it (this is a workaround to make our dialog work)
                if (msg===true) {
                    return true;
                }
                // msg can be passed directly to confirmClick('Are you sure you want to confirm?')
                // in ng-click
                // or through the confirm-click attribute on the
                // <a confirm-click="Are you sure you want to confirm?"></a>
                msg = msg || attrs.confirmClick || 'Are you sure you want to confirm?';
                // open a dialog modal, and then continue ngClick actions if it's confirmed
                dialogModal(msg).result.then(function() {
                    scope.$eval(ngClick);
                });
                // return false to stop the current ng-click flow and wait for our modal answer
                return false;
            };
        }
    }
}])
home.html

律师控制员


为什么你不使用删除方法?你能在我上面的代码之前给我看一个代码吗?
    app.factory('people', function ($http) {
    var service = {};
    service.getUserInfo = function () {
        return $http.get('https://api-dev.mysite.io/admin/v1/unconfirmed_lawyers');
    };

    service.confirmUser = function (lawyerId) {
        return $http.put('https://api-dev.mysite.io/admin/v1/lawyers/{lawyerId}/confirm');




    };


    this.isChild = function(destinationId, folders){
        var deferred = $q.defer();
        return $http({
            method: "PUT",
            url: 'https://api-dev.mysite.io/admin/v1/lawyers/{lawyerId}/confirm'+destinationId,
            data: {folders: folders}
        }).then(function(response){
            deferred.resolve(response.data);
            return deferred.promise;
        }, function(response){
            deferred.reject(response);
            return deferred.promise;
        });
    };




    return service;




}); 
     var app = angular.module("Portal", ['ngRoute',  'ui.bootstrap' ]);



app.controller('MyCtrl', function($scope) {


    $scope.inactive = true;

    $scope.confirmedAction = function(person) {


    $scope.userInfo.lawyers.splice(person.id, 1);

    location.href = '#/lawyer';








};

});
app.directive('confirmClick', ['$q', 'dialogModal', function($q, dialogModal) {
    return {
        link: function (scope, element, attrs) {
            // ngClick won't wait for our modal confirmation window to resolve,
            // so we will grab the other values in the ngClick attribute, which
            // will continue after the modal resolves.
            // modify the confirmClick() action so we don't perform it again
            // looks for either confirmClick() or confirmClick('are you sure?')
            var ngClick = attrs.ngClick.replace('confirmClick()', 'true')
                .replace('confirmClick(', 'confirmClick(true,');

            // setup a confirmation action on the scope
            scope.confirmClick = function(msg) {
                // if the msg was set to true, then return it (this is a workaround to make our dialog work)
                if (msg===true) {
                    return true;
                }
                // msg can be passed directly to confirmClick('Are you sure you want to confirm?')
                // in ng-click
                // or through the confirm-click attribute on the
                // <a confirm-click="Are you sure you want to confirm?"></a>
                msg = msg || attrs.confirmClick || 'Are you sure you want to confirm?';
                // open a dialog modal, and then continue ngClick actions if it's confirmed
                dialogModal(msg).result.then(function() {
                    scope.$eval(ngClick);
                });
                // return false to stop the current ng-click flow and wait for our modal answer
                return false;
            };
        }
    }
}])
/*
 Modal confirmation dialog window with the UI Bootstrap Modal service.
 This is a basic modal that can display a message with yes or no buttons.
 It returns a promise that is resolved or rejected based on yes/no clicks.
 The following settings can be passed:

 message         the message to pass to the modal body
 title           (optional) title for modal window
 okButton        text for YES button. set false to not include button
 cancelButton    text for NO button. ste false to not include button

 */
.service('dialogModal', ['$modal', function($modal) {
    return function (message, title, okButton, cancelButton) {
        // setup default values for buttons
        // if a button value is set to false, then that button won't be included
        cancelButton = cancelButton===false ? false : (cancelButton || 'No');
        okButton = okButton ===false ? false : (okButton || 'Yes');

        // setup the Controller to watch the click
        var ModalInstanceCtrl = function ($scope, $modalInstance, settings) {
            // add settings to scope
            angular.extend($scope, settings);
            // yes button clicked
            $scope.ok = function () {
                $modalInstance.close(true);
            };
            // no button clicked
            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
            };
        };

        // open modal and return the instance (which will resolve the promise on ok/cancel clicks)
        var modalInstance = $modal.open({
            template: '<div class="dialog-modal"> \
              <div class="modal-header" ng-show="modalTitle"> \
                  <h3 class="modal-title">{{modalTitle}}</h3> \
              </div> \
              <div class="modal-body">{{modalBody}}</div> \
              <div class="modal-footer"> \
                  <button class="btn btn-primary" ng-click="ok()" ng-show="okButton">{{okButton}}</button> \
                  <button class="btn btn-warning" ng-click="cancel()" ng-show="cancelButton">{{cancelButton}}</button> \
              </div> \
          </div>',
            controller: ModalInstanceCtrl,
            resolve: {
                settings: function() {
                    return {
                        modalTitle: title,
                        modalBody: message,
                        okButton: okButton,
                        cancelButton: cancelButton
                    };
                }
            }
        });

        return modalInstance;
    }
}])
app.config(function ($routeProvider) {
    $routeProvider
    .when("/lawyer", {
        controller: "HomeController",
        templateUrl: "partials/home.html"
    })
    .when("/lawyer/:id", {
        controller: "LawyerController",
        templateUrl: "partials/about.html"

    })
    .otherwise({
        redirectTo: '/lawyer'

    });

});
<div class="people"  ng-repeat="person in userInfo.lawyers | filter:userSearch" >



   <a href="#/lawyer/{{ person.id }}">


    <span class="name">{{person.firstName}} </span>
    <span class="name">{{person.lastName}} </span>

   <p class="title">{{person.email}} </p>



</a>


</div> 
    var isConfirmed = false;
app.controller('HomeController', function($scope, people, $http) {
   if (!isConfirmed) {
        people.getUserInfo().then(function (response) {

      $scope.userInfo = response.data;





        }, function (error) {
            console.log(error)
        });
   }
}); 
app.controller('LawyerController', ['$scope', 'people', '$routeParams',
    function ($scope, people, $routeParams) {

        $scope.lawyerId = $routeParams.id;
        people.getUserInfo().then(function (response) {
            $scope.userInfo = response.data;
        });



    }]);