我试图获取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
});
}
答案 0 :(得分:0)
您需要在控制器中注入$ 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);
});
答案 1 :(得分:0)
在bootstrap之前,你需要掌握注入器并手动获取$ http服务。
var initInjector = angular.injector(["ng"]);
var $http = initInjector.get("$http");
$http.get