我正在尝试获取json数据,并使用angularjs将它们保存在本地存储中,但是此错误“无法读取未定义的属性'get'的未定义”出现在inspect元素上有任何帮助吗?

function getData($http,callback){
        //callback();
        $http.get(server + "/CrewServices/adminConsole/adminData")
                .success(function(data, status, headers, config) {
                    app.value('adminData', data);
                    var Roles=unique(data.roles);
                    localStorage.setItem("currLoggedUSer", data.userName);
                    localStorage.setItem("currLoggedUSerRoles", Roles);
                    angular.forEach(data.airlines, function (key) {
                        if( key == 0 && localStorage.getItem("selectedAirline") == null ){
                            localStorage.setItem("selectedAirline", data.airlines[key].airline);
                            localStorage.setItem("selectedAirlineApiKey", data.airlines[key].key);
                        }
                    });
                    callback();
                })
                .error(function(data, status, headers, config) {
                    // log error
                });
    }

最佳答案

您需要将$ http注入到控制器中。 Here's more info in the Angular documentation.

var myApp = angular.module('myApp',[]);
myApp.controller('Controller', function($scope, $interval, $http){

    $interval(function($scope, $http){

        $http.get('test.json').success(function(data){

        });
    },5000);

});

09-25 15:24