我想从外部范围访问变量。我想使用最佳实践从外部访问变量。
我的要求:让我告诉我在一个范围内生成url的情况,从此成功范围中的select选项中收集数据,在下一次成功中,我将使用此url获取json数据,如何我会做的
DEMO: http://plnkr.co/edit/wIk0dwiDwgWlOLrAvjX5?p=preview
$http.get("data.json") // this will give some data from which i will made select options
.success(function(response) {
// generate dynamic url
var dyanamic_url="http://192.168.206.133:8080/admin/metering/<select_options>;
//alert(url);
});
//I wanted to use this dyanamic_url outside scope.
//Outside the scope of success.
$http.get(dyanamic_url)
.success(function(response) {
// Fetch JOSN DATA
})
会继续工作吗?
.success(function (response) {
var url = response.someproperty;
http$.get(url).success(function(respone ))
});
答案 0 :(得分:0)
无需访问该范围内的url
。相反,只需在成功回调中发送第二个请求。
.success(function (response) {
var url = response.someproperty;
sendAnotherRequest(url);
});