0
我有一个关于Cordova程序中变量范围的问题。范围变量AngularJS
这是我的代码:
angular.module('starter.services', [])
.factory('myFactory', function ($http) {
var myVar = "HELLO";
alert(myVar); //HELLO -> Correct
$http.get("URL").then(
function (response) {
myVar = response.data;
alert(myVar) // Correct Answer
}, function (error) {
console.log("Get config.json error - " + JSON.stringify(error));
}
);
alert(serverName); //HELLO -> why?
我宣布我的HTTP块外部变量。你可以帮我吗?谢谢
可能想再次检查该代码。 'alert(serverName)'会给出未定义的代码,上面显示的代码。 –