变量是不是在HTTP $共享范围 [英] variable is not shareable in http $scope

查看:131
本文介绍了变量是不是在HTTP $共享范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$http({
    url: "php/InsertTab.php",
        method: "POST",
        data: {
            'userId': userId,
        },
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        }).success(function(data, status, headers, config) {

        myVar = data;

        }).error(function(data, status, headers, config) {
    });

console.log(myVar);

可变量myVar的是份额/是$ HTTP范围之外的访问?我写的console.log(myVar的)之外,它返回空白?

can variable myVar be share / be access outside the scope of $http? I wrote console.log(myVar) outside it returned blank?

推荐答案

u必须要使用的$ HTTP之外myVar的使用角度$ Q服务。
尝试读取这个页面: https://docs.angularjs.org/api/ng/service/ $ q

u have to use angular $q service in order to use myVar outside of $http. try reading in this page : https://docs.angularjs.org/api/ng/service/$q

这篇关于变量是不是在HTTP $共享范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆