我收到了这个错误
参数' 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));
});
}
}
不确定我哪里出错了,我已经将FreshlyPressed作为AppCtrl函数的参数。
答案 0 :(得分:0)
您必须更改行
来自
App.controller("AppCtrl", "FreshlyPressed", ["$scope", "$log", AppCtrl]);
要强>
App.controller("AppCtrl", ["$scope", "$log", "FreshlyPressed", AppCtrl]);
控制器功能也应该是这样的
function AppCtrl($scope, $log, FreshlyPressed){
$scope.refresh = function(){
FreshlyPressed.getBlogs();
}
}