[Service Portal] Overriding angular directives
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2019 08:03 AM
Curious if there is any documentation on overriding angular directives in Service Portal? I want to overwrite the <sp-help-tag> directive. I thought it could be done using an angular provider. I found an example of how to accomplish this for the `spModel` directive, in this article
function(spModelDirective) {
return angular.extend({}, spModelDirective[0], {
templateUrl : 'custom_model.xml'
});
}
I tried this:
function(spHelpTagDirective) {
return angular.extend({}, spHelpTagDirective[0], {
templateUrl : 'custom_help.xml'
});
}
That doesn't seem to be working. Any ideas? I may not have the syntax correct.
The piece I am confused about is why is the directive in the example above is referred to as "spModelDirective" and not just "spModel". Looking at the source code in the console:
The directive is called 'spModel'. The same for 'spHelpTag':
It seems simple enough to just create a new angular directive, and a provider to point to the new template. I also noticed there is a difference between the two directives:
'spModel' has
return attrs.templateUrl || sp_model.xml
Whereas the 'spHelpTag' does not. Wondering if that may be why it isn't possible to extend the directive?
Ultimately, I would like to change the functionality of the 'sp-help-tag' directive, so if anyone has any ideas, feel free to chime in!
Cheers!
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 12:55 PM
I personally don't like the approach with $timeout(function() {...}, 350, false);. 350 ms is long enough and the user will see elements, which you hide and the picture will flicker.
Do you tried my suggestion? You can see that it has setTimeout(function () {...}, 0); with 0 as timeout. In all my tests it works.
I understand that it would be good to have a way to execute some code after all dependent widgets of sp-model have been loaded, but I don't know any event, which will be triggered at the moment. So I have no idea how to solve your problem on elegant way. One can of cause create custom directives with the copy of spModal, spFormField, spVariableLayout and spCheckboxGroup and modified templates, but it will be a lot of copy of existing code and it will be difficult to maintain the code after ServiceNow publish patches and new versions.
