2013-12-22 50 views
-1

我第一次嘗試AngularJS和我卡在我的第一個get方法。AngularJS JSON GET從PHP文件

凡在jQuery的我會使用$阿賈克斯()我已經得到了下面,我得到一個錯誤

var theApp = angular.module('theApp', []); 
theApp.controller('ContentController', ['$scope', function ($scope) { 

}]); 
theApp.controller('MenuSideController', ['$scope', function ($scope, $http) { 
    $http.get('/directory/assets/inc/category.php').success(function(data) { 
     $scope.list = data; 
    }); 

}]); 

的錯誤,我得到

TypeError: Cannot call method 'get' of undefined 

回答

3

你不指定字符串版本$http在您的參數列表中,所以Angular不通過該服務。

更改此行:

theApp.controller('MenuSideController', ['$scope', function ($scope, $http) 

要這樣:

theApp.controller('MenuSideController', ['$scope','$http', function ($scope, $http)