AngularJS不确定是不是在我的情况下,一个功能错误
问题描述:
我得到这个错误代码如下:AngularJS不确定是不是在我的情况下,一个功能错误
TypeError: undefined is not a function
at Scope.AppCtrl.$scope.refresh
我分前端,用于NG-重复
<ion-content>
<div class="card list" data-ng-repeat="p in posts">
<div class="item item-avatar-left">
<img data-ng-src="{{p.author.avatar_URL}}">
<h2>{{p.author.nice_name}}</h2>
<p><a href="{{p.author.URL}}"></a>{{p.author.URL}}</p>
</div>
<div class="item item-body">
<h1>{{p.title}}</h1>
<p>{{p.content}}</p>
</div>
</div>
</ion-content>
我app.js文件
var App = angular.module('App', ['ionic']);
App.service("FreshlyPressed", ["$http","$log",FreshlyPressed]);
App.controller("AppCtrl", ["$scope", "FreshlyPressed", "$log", AppCtrl]);
function AppCtrl($scope, $log, FreshlyPressed){
$scope.posts = [];
$scope.refresh = function(){
FreshlyPressed.getBlogs($scope);
}
}
function FreshlyPressed($http, $log){
this.getBlogs = function($scope){
$http.jsonp("https://public-api.wordpress.com/rest/v1/freshly-pressed?callback=JSON_CALLBACK")
.success(function(result){
$scope.posts = result.posts;
});
}
}
我通过$范围,并期望它的工作,但我得到了一个undienfed错误在线FreshlyPressed.getBlogs($scope);
答
看起来像你的依赖注入顺序不正确
App.controller("AppCtrl", ["$scope", "FreshlyPressed", "$log", AppCtrl]);
变化
App.controller("AppCtrl", ["$scope", "$log","FreshlyPressed", AppCtrl]);
确实顺序回事? – 2014-11-24 05:32:12
是的,它确实很重要。 :)根据传递的参数FreshlyPressed引用$ log,但是$ log没有任何称为getBlogs的方法。 – 2014-11-24 05:36:48