Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何从$resource访问$scope_Angularjs_Angularjs Scope_Angularjs Service - Fatal编程技术网

Angularjs 如何从$resource访问$scope

Angularjs 如何从$resource访问$scope,angularjs,angularjs-scope,angularjs-service,Angularjs,Angularjs Scope,Angularjs Service,我需要在成功时拼接阵列。如何回调$scope.list以从列表数组中删除项?我应该这样做还是有更好的方法?比如说“更新”之类的 var phonecatServices = angular.module('phonecatServices', ['ngResource']); var urlBase = 'http://example.com/api/'; function resourceErrorHandler(response) { console.lo

我需要在成功时拼接阵列。如何回调$scope.list以从列表数组中删除项?我应该这样做还是有更好的方法?比如说“更新”之类的

var phonecatServices = angular.module('phonecatServices', ['ngResource']);
    var urlBase = 'http://example.com/api/';

    function resourceErrorHandler(response) {

        console.log("error");
    }
    function resourceResponseHandler(response) {
        console.log($scope.list);

        $scope.list.data.splice(index, 1);
        console.log("success");
    }
    phonecatServices.factory('api_resource', ['$resource',
      function($resource){
        return $resource(urlBase+':api_resource/:id.json', {}, {
          query: {method:'GET', isArray:false},
          save:{method:'POST', isArray:false},
          delete:{method:'DELETE', isArray:false, interceptor:{response:resourceResponseHandler, responseError:resourceErrorHandler}},
         });
      }]);

将$scope作为函数中的参数,并将其与控制器中的方法调用一起传递,或将其捆绑到响应对象中