如何在 $scope.myfunction() 函数中做 http Crud 操作?

How to do http Crud operations in in $scope.myfunction() function?

我使用 meanjs 生成器来获取此代码

Mycode :- 从 servercontroller 查询数据。但是我需要使用 Http 请求从 Api 服务器获取数据。所以我尝试使用 Http

编写如下代码

SuperherosController.js

 angular.module('superheros').controller('SuperherosController', ['$scope','$http', '$stateParams', '$location', 'Authentication', 'Superheros',
    function($scope, $stateParams, $location, Authentication, Superheros,$http) {
        $scope.authentication = Authentication;
// *Find a list of Superheros*
        $scope.find = function() {
   //Actual code with out Http request 
           // $scope.superheros =  Superheros.query();
   /// *The code i tried with  Http and injected dependencies* 

//行56:13 $http.get('http://api.xxx.com/superheros').成功(函数(数据){ $scope.superheros = 数据; }); }; } ]);

**通过上述修改 http.get 提出请求但出现错误:-

错误**

$http.get(...).success is not a function $scope.find@http://localhost:3000/modules/superheros/controllers/superheros.client.controller.js:56:13

错误:[$resource:badcfg]资源配置错误。预期响应包含一个对象,但得到一个数组 ,其中一些引用 angular 域

你能告诉我我的代码有什么问题吗..或者我该如何解决这个问题? 提前感谢您的帮助!!

你的模块的顺序在函数中也必须有相同的顺序

function($scope, $http, $stateParams, $location, Authentication, Superheros)

$http 在 $scope 之后,因为您按此顺序定义了模块