Skip to content

Instantly share code, notes, and snippets.

@boneskull
Last active December 20, 2015 11:59
Show Gist options
  • Save boneskull/6127098 to your computer and use it in GitHub Desktop.
Save boneskull/6127098 to your computer and use it in GitHub Desktop.
Potentially useless and harmful example of coercing a jQuery $.Deferred out of AngularJS' $q. See http://jsfiddle.net/boneskull/TX7fA/
var myApp = angular.module('myApp', []);
$(function () {
var body = $('body'),
injector = body.injector(),
giveMeJQueryPromise = function ($log, $timeout) {
var dfrd = $.Deferred();
$log.log('deferring');
$timeout(angular.noop, 2000).then(function () {
dfrd.resolve('deferred');
});
return dfrd.promise();
};
jqpromise = injector.invoke(giveMeJQueryPromise);
jqpromise.then(function (res) {
console.log(res);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment