0

I have a very simple directive

.directive('myDirective', ['$window', function ($window) {
    return {
        restrict: 'AE',
        scope: {
            ...
        },
        link: function ($scope) {
            
        },
        template:
            '<SOME HTML...>'
           
    };
}])
            

I need to execute some code once the directive is loaded. What I tried is to put inside link this:

element.on('load', function(event) {
    console.log('loaded');
});

with no luck. What else should I do? Thanks.

user3174311
  • 1,714
  • 5
  • 28
  • 66
  • 1
    something like an init? https://stackoverflow.com/questions/33342437/calling-a-init-function-when-a-directive-is-loaded – cmgchess Jun 27 '22 at 15:54
  • no need to do anything. just put your code in the begining of scope {... here} at start it will work and will never run again for that element until recreation by browser – Mehmet_ Jul 03 '22 at 11:04

0 Answers0