0

I have a following method

        mute: function (action) {
            var deferred = $q.defer();
            function muteRec() {
                return jQuery.muteRec({
                    user: name,
                    action: action || 'mute',
                    ajaxSettings: {
                        suppressWarnings: true
                    }
                });
            }

            if (jQuery.muteRec) {
                deferred.resolve(muteRec());
            } else {
                this.loadCCRecordingScript()
                    .then(function () {
                        deferred.resolve(muteRec());
                    })
                    .catch(function () {
                        $rootScope.recordingNotavailable = true;
                        deferred.reject();
                    });
            }

            return deferred.promise;
        }

I am new to jquery , What i wants that Instead of resolving the promise with another promise, I have to use success and error callbacks of jquery in muteRec and resolve or reject the promise in there.

Nakul
  • 35
  • 5
  • Why would you want that? Resolving a promise with another promise is the proper way. Or does `$.muteRec` not support promises? – Bergi Jun 15 '17 at 12:04
  • Also, avoid the [deferred antipattern](https://stackoverflow.com/q/23803743/1048572?What-is-the-promise-construction-antipattern-and-how-to-avoid-it)! You should not use `$q.defer();` when you are working with already promise-returning functions. – Bergi Jun 15 '17 at 12:06
  • $.muteRec not supports promises – Nakul Jun 15 '17 at 12:20
  • Then what does it do, why does it take ajaxsettings? Please link its documentation. – Bergi Jun 15 '17 at 16:50

0 Answers0