Any way to know if a variable is an angularjs promise?

后端 未结 4 1573
情书的邮戳
情书的邮戳 2020-12-14 14:33

I\'m making a directive that takes a function as a scope parameter (scope: { method:\'&theFunction\' }). I need to know if the result returned by that metho

4条回答
  •  离开以前
    2020-12-14 14:58

    @kayakDave, thanks for guiding to right place.

    angular $q

    when(value, [successCallback], [errorCallback], [progressCallback]);
                Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. 
                This is useful when you are dealing with an object that might  or might not be a promise, 
                or if the promise comes from a source that can't be trusted.
    
    $q.when(value).then(function (data) {
    //this helps me to bind data from $resource or $http or object
    }
    

    check this fiddle

提交回复
热议问题