2014-11-24 80 views
0

我得到這個錯誤代碼如下: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);

回答

1

看起來像你的依賴注入順序不正確

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

變化

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

確實順序回事? – 2014-11-24 05:32:12

+0

是的,它確實很重要。 :)根據傳遞的參數FreshlyPressed引用$ log,但是$ log沒有任何稱爲getBlogs的方法。 – 2014-11-24 05:36:48

相關問題