$document and $window: Use $document
and $window
at all times to aid testing and Angular references
// avoid
function dragUpload () {
return {
link: function ($scope, $element, $attrs) {
document.addEventListener('click', function () {
});
}
};
}
// recommended
function dragUpload () {
return {
link: function ($scope, $element, $attrs, $document) {
$document.addEventListener('click', function () {
});
}
};
}
$timeout and $interval: Use $timeout
and $interval
over their native counterparts to keep Angular's two-way data binding up to date
// avoid
function dragUpload () {
return {
link: function ($scope, $element, $attrs) {
setTimeout(function () {
//
}, 1000);
}
};
}
// recommended
function dragUpload ($timeout) {
return {
link: function ($scope, $element, $attrs) {
$timeout(function () {
//
}, 1000);
}
};
}