Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.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
Javascript 服务未能注入控制器_Javascript_Angularjs - Fatal编程技术网

Javascript 服务未能注入控制器

Javascript 服务未能注入控制器,javascript,angularjs,Javascript,Angularjs,我犯了这个错误 参数“AppCtrl”不是函数,获取字符串 我的app.js如下: var App = angular.module('App', ['ionic']); App.service("FreshlyPressed", ["$http","$log",FreshlyPressed]); App.controller("AppCtrl", "FreshlyPressed", ["$scope", "$log", AppCtrl]); function AppCtrl($scope,

我犯了这个错误

参数“AppCtrl”不是函数,获取字符串

我的app.js如下:

var App = angular.module('App', ['ionic']);

App.service("FreshlyPressed", ["$http","$log",FreshlyPressed]);
App.controller("AppCtrl", "FreshlyPressed", ["$scope", "$log", AppCtrl]);

function AppCtrl($scope, FreshlyPressed, $log){
  $scope.refresh = function(){
    FreshlyPressed.getBlogs(); 
  }
}

function FreshlyPressed($http, $log){
    this.getBlogs = function(){
        $http.jsonp("https://public-api.wordpress.com/rest/v1/freshly-pressed?callback=JSON_CALLBACK")
        .success(function(result){
            $log.info(JSON.stringify(result.posts));
        });
    }
}

不确定哪里出错了,我已经在AppCtrl函数中新按了as param。

您必须更改行

来自

App.controller("AppCtrl", "FreshlyPressed", ["$scope", "$log", AppCtrl]);

App.controller("AppCtrl", ["$scope", "$log", "FreshlyPressed", AppCtrl]);
控制器的功能应该是这样的

function AppCtrl($scope, $log, FreshlyPressed){
  $scope.refresh = function(){
    FreshlyPressed.getBlogs(); 
  }
}

哎呀,我搞砸了。但是参数的顺序在控制器函数中真的很重要吗?不,但是当使用更多参数时,它应该很容易处理:)用第一个答案检查这一点,它会很有用