- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 12:39 AM
Hi,
I am currently creating a new Angular.js directive for my company. I like to use the $onInit function to initialize code. This usually works fine. But when I want $onInit to initialize my Angular Directive it just doesn't fire at all.
See this snippet here:
function myDirective() {
return {
controller: function($scope) {
var c = this;
c.$onInit = function() {
console.log('myDirective $onInit fired...'); // <-- this never happens
}
},
restrict: 'E',
scope: {
myVar: '='
}
template: '<div>Some HTML templating...</div>'
};
}
The code above should work fine - except that c.$onInit has absolutely no effect. $onInit does not seem to be called inside the directive.
Is there a known issue inside ServiceNow Angular.js directives? I found some reports that Angular.js has this behaviour when a controller gets initialized by ngRoute. Is this maybe happening in the background?
Thanks and regards,
Tobias
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 12:48 AM
I have no idea what changed... searched 1 hour to find out why it is not working. And no it suddenly just triggered the $onInit without any issues. And as I said... no idea what did the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 12:48 AM
I have no idea what changed... searched 1 hour to find out why it is not working. And no it suddenly just triggered the $onInit without any issues. And as I said... no idea what did the trick.