2014-12-13 97 views
0

我試圖顯示一個通過AJAX遠程訪問的對象。目前我得到的錯誤是:通過遠程AJAX請求角度獲取和顯示對象

ReferenceError: $stateParams is not defined 

下面是我在services.js

.factory('Games', function() { 
    var games = $.ajax({ 
    "url":"https://www.kimonolabs.com/api/dc6n4edu?apikey=[APIKEY]&callback=kimonoCallback", 
    "crossDomain":true, 
    "dataType":"jsonp" 
    }); 

    return { 
    all: function() { 
     return games; 
    }, 
    get: function(gameID) { 
     // Simple index lookup 
     return games[gameId]; 
    } 
    } 
}); 

下面是我在controller.js

.controller('AccountCtrl', function($scope, Games) { 
    console.log("test in controller"); 
    $scope.game = Games.get($stateParams.gameId); 
}); 

以下是我在tab-account.html

<ion-list> 
     <ion-item ng-repeat="item in items"> 
     Hello, {{item}}! 
     </ion-item> 
    </ion-list> 
+0

什麼類型的呼叫是$ AJAX?得到職位? – 2014-12-13 18:48:55

+0

這是一個GET返回一個對象+數組 – beaconhill 2014-12-13 18:55:42

+0

$ stateParams與ui-router相關。你可以在你的導航路線定義的地方給app.js代碼。配置(函數($ stateProvider,$ urlRouterProvider){$ ...... stateProvider.state $ – 2014-12-13 20:18:14

回答

0

你缺少控制器功能$stateParams值...但我認爲你應該考慮使用$http服務或resource

.controller('AccountCtrl', function($scope, $stateParams, Games) { 
     console.log("test in controller"); 
     $scope.game = Games.get($stateParams.gameId); 
    });