nshanmugamram
3/14/2018 - 1:50 PM

Promise examples

Promise examples

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>

<script id="jsbin-javascript">
$injector = angular.injector(['ng']);
q = $injector.get('$q'); 

function  test1(){
 return q.when;
}

function  test2(){
  return q.when;
}

q.all([test2,test1]) .then(function(){
  console.log('2');
})

function  test3(){
 return q.when();
}

function  test4(){
  return q.when;
}
//you can do like this
test3().then(test4) .then(function(){
  console.log('21');
})

//you can not do like this
test4().then(test4) .then(function(){
  console.log('21');
})

//call this
test3();
</script>



<script id="jsbin-source-javascript" type="text/javascript">$injector = angular.injector(['ng']);
q = $injector.get('$q'); 

function  test1(){
 return q.when;
}

function  test2(){
  return q.when;
}

q.all([test2,test1]) .then(function(){
  console.log('2');
})

function  test3(){
 return q.when();
}

function  test4(){
  return q.when;
}
//you can do like this
test3().then(test4) .then(function(){
  console.log('21');
})

//you can not do like this
test4().then(test4) .then(function(){
  console.log('21');
})

//call this
test3();</script></body>
</html>