0

I wrote some code for promise understanding:

function test1() {
    return $http.get("google.com").then(function (data) {
        console.log("OK1");
    }, function (data) {
        console.log("ERROR1");
    });
}

$scope.test = function() {
    test1().then(function (data) {
        console.log("OK2");
    }, function (data) {
        console.log("ERROR2");
    });        
}

And when I try execute this I get ERROR 1 OK2 but I expect ERROR1 ERROR2.

How understand that?

Full example: http://jsfiddle.net/HB7LU/14804/

wtrclr
  • 105
  • 8
  • Why not just use `.success` and `.error` instead? – ryanyuyu Jun 30 '15 at 20:33
  • Would you also have expected to get the `data` from the request in the second handler? No, promises returned by `then` resolve with the results from the callback(s). – Bergi Jun 30 '15 at 20:37
  • 1
    @ryanyuyu This is very simplified example. In my real app `test1` and `test` function located in different unit. – wtrclr Jun 30 '15 at 20:38

0 Answers0