$q的基本用法
angularjs的http是异步的没有同步,一般都会遇到一个场景,会把异步请求的参数作为条件执行下一个函数,之前一直在看其他人的博客理论太多看了很久才看懂
http({
method:'post',
url:'aaa',
}).success(function(data){
$scope.flag=true;
});
//当回调函数没有成功时, 不会打印,当然也可以把打印放在回调函数中。
if($scope.flag){
alert("回调成功");
}
接下来看$q的使用
$scope.call=function(){
var deferred = $q.defer();
http({
method:'post',
url:'aaa',
}).success(function(data){
deferred.resolve('Hello, ' + name + '!');
$scope.flag=true;
});
return deferred.promise;
};
//这样就可以等回调成功后才会打印。
$scope.call().then(function(){
alert("success");
},function(){
alert("error");
});
随机推荐
- Emscripten 安装和使用
OS: Windows 10 x64 I. install 0. pre install Python2.7 Node js Java 1. down git clone https://github ...
- Vue中table表头合并的用法
<div class="panel-container"> <div> <table class="table-head" wid ...
- Servlet的几个关键知识点
1.ServletConfig ServletConfig是Servlet的配置文件.对应于web.xml中的<servlet></servlet>标签.ServletConf ...
- netbeans 正则替换
单引号替换为双引号: tablename1('xhw_aa') tablename2('xhw_bb') tablename3('xhw_cc') tablename4('xhw_dd') (t ...
- c#随机生成英文名
private static string GenerateSurname() { string name = string.Empty; string[] currentConson ...
- 《Spring_Four》第一次作业:团队亮相
part one: 1.队名:Spring_Four 2.团队成员组成:学号/姓名(标记团队组长) 201571030114 李蕾 201571030143 周甜甜 201571030139 张天旭( ...
- eclipse git(版本回退)
https://www.cnblogs.com/duex/p/6389999.html
- cdnbest配置强制ssl跳转
如何配置强制ssl跳转 1. 登陆用户站点,点击下图图标: 2. 如下图添加证书和开启强制ssl即可 hsts解释和作用: 国际互联网工程组织IETF正在推行一种新的Web安全协议HTTP Stric ...
- 大数据入门到精通8-spark RDD 复合key 和复合value 的map reduce操作
一.做基础数据准备 这次使用fights得数据. scala> val flights= sc.textFile("/user/hdfs/data/Flights/flights.cs ...
- 好看的alert弹出框sweetalert
转载:https://www.cnblogs.com/lamp01/p/7215408.html