2014-11-24 59 views
0

我得到這個錯誤服務未能注入控制器

參數 '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

你必須改變線路

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

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

而且還控制器功能應該是這樣的

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

哎呀我搞砸了。但是param的順序在控制器功能中真的很重要嗎? – 2014-11-24 04:57:53

+0

不,但它應該很容易處理,當使用更多的參數:) – jamseernj 2014-11-24 04:59:29

+0

看看這個與第一個答案它將是有用的 http://stackoverflow.com/questions/19238191/understanding-angular-js-controller-parameters – jamseernj 2014-11-24 05:03:33