0
我设置了配置参数,但console.log()
返回我undefined
,我无法理解为什么,我看到从控制台中的http调用返回的json!
app.run(function($rootScope, $location,$http){
var update = function(){
$rootScope.config = {};
$rootScope.config.app_name = "Appname";
$rootScope.config.app_short_description = $rootScope.config.app_name+" helps you go out with your rabbit";
$rootScope.config.app_motto = "hey ohhhhhhhhhh <i class='icon-check'></i>";
$rootScope.config.app_url = $location.url();
$rootScope.config.app_path = $location.path();
$http.get('jsons/json.json').success(function(response) {
$rootScope.config.app_genres = response.data;
});
console.log($rootScope.config.app_genres);
}
$rootScope.$on('$routeChangeStart', function(){
update();
});
});
现在真的很清楚了!但为什么它仍然返回undefined即使你的例子? :O – sbaaaang
offtopic,它不应该是@scope而不是$ rootScope? –
@RoyiNamir取决于sbaaaang将如何处理它,如果它是一些全局共享配置$ rootScope可能会好,但AngularJS服务可能更好(?)。 – Philipp