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

时间:2015-03-03 07:19:31

标签: angularjs-scope meanjs

我使用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 = data;                 });              };             }         ]);

**通过上面的修改http.get发出请求但是有一个错误提升: -

ERROR **

  

$ http.get(...)。成功不是一个功能   $ scope.find @ http://localhost:3000/modules/superheros/controllers/superheros.client.controller.js:56:13

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

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

1 个答案:

答案 0 :(得分:0)

模块的顺序在功能中也必须具有相同的顺序

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

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

相关问题