Answer the question
In order to leave comments, you need to log in
Why does the Cannot read property 'defer' of undefined error appear?
Good day. I needed to make the timeout option for promice into angular for the $q library.
In the open spaces of the bourgeoisie, I found an article where the ability to create a timeout is added through a decorator ( the article itself )
I did everything according to the instructions, I got the following code:
$provide.decorator('$q', function decorateQ($delegate) {
// $delegate is the native angular $q service
var _defer = $delegate.defer;
// keep the original $q.defer function
$delegate.defer = function newDefer() {
var d = _defer(); // create the deferred object as before
d.promise.timeout = function (ms, callback) {
setTimeout(function () {
if (pending) {
cb(callback);
}
}, ms);
};
return d;
};
});
Uncaught TypeError: Cannot read property 'defer' of undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question