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

后端 未结 4 1588
情书的邮戳
情书的邮戳 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 15:05

    Angular's when() is a good option as Davin mentioned.

    If that doesn't meet your needs then Angular's internal way of checking (it uses this inside when) is very close to what you're doing:

    var ref = function(value) {
       if (value && isFunction(value.then)) {
          // Then this is promise
       }
    

提交回复
热议问题