Javascript 服务未能注入控制器
我犯了这个错误 参数“AppCtrl”不是函数,获取字符串 我的app.js如下: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,
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();
}
}
哎呀,我搞砸了。但是参数的顺序在控制器函数中真的很重要吗?不,但是当使用更多参数时,它应该很容易处理:)用第一个答案检查这一点,它会很有用