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

后端 未结 4 1576
情书的邮戳
情书的邮戳 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:56

    The $q.when() answer seems like the best answer for most use cases, I used instanceof for mine.

        if(buttonData instanceof $q) {
            buttonData.then(function(actions) {
                $scope.buttonActions = actions;
            });
        } else {
            $scope.button = buttonData;
        }
    

    Alternatively, the following IF worked as well, but I ended up going with the above solution.

    if(Object.getPrototypeOf(buttonData) === $q.prototype) {

提交回复
热议问题