-
Notifications
You must be signed in to change notification settings - Fork 1
/
angular-dom-events.js
executable file
·44 lines (41 loc) · 1.12 KB
/
angular-dom-events.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function(window, angular, undefined) {
'use strict';
angular.module('ngDomEvents', [])
/**
* @ngdoc directive
* @name ngDomEvents.directive:domOnCreate
* @description
* # domOnCreate
*/
.directive('domOnCreate', function($parse, $timeout) {
return {
link: function postLink(scope, element, attrs) {
// wrap in a timeout to allow directives to link scope callbacks
$timeout(function() {
if (attrs.domOnCreate) {
$parse(attrs.domOnCreate)(scope);
}
});
}
};
})
/**
* @ngdoc directive
* @name ngDomEvents.directive:domOnDestroy
* @description
* # domOnDestroy
*/
.directive('domOnDestroy', function($parse) {
return {
link: function postLink(scope, element, attrs) {
var destroyHandler;
if (attrs.domOnDestroy) {
destroyHandler = $parse(attrs.domOnDestroy);
element.on('$destroy', function() {
destroyHandler(scope);
});
}
}
};
})
})(window, window.angular);