Using Angular Service Providers in Service Portal

jonlind
Giga Contributor

Hello.   I'm trying to create an Angular Service Provider to share information amongst widgets.   There seem to be a lot of examples of Directives, but I have not been able to find an example of an Angular Service Provider in Service Portal for ServiceNow (you can see how this might be a tough item to search for).

Being intrepid I tried it anyway, and went and created a new Angular Provider of type "Service", named it "breadcrumbServiceProvider", and added it to the Angular Provider related list on my widget.

The widget's client script declaration looks like this:

Screen Shot 2016-06-06 at 11.40.16 AM.png

The error I get from the browser on load is:

js_includes_sp.jsx?v=05-03-2016_1034&lp=Wed_May_04_13_01_59_PDT_2016&c=11_202:11755 Error: [$injector:unpr] Unknown provider: breadcrumbServiceProvider <- breadcrumbService

The provider is configured thusly:

Screen Shot 2016-06-06 at 11.43.20 AM.png

So the question is: how do you set up and inject a Widget Angular Service Provider?

1 ACCEPTED SOLUTION

fschuster
ServiceNow Employee
ServiceNow Employee

Hi Jon,



If I'm not mistaken you have to provide the name of the Service Provider to your controller - in your case that should be breadcrumbServiceProvider instead of breadcrumb.



Just built a quick example (based on this tutorial) to try and show-case. Worked fine for me:



Service2.pngService3.pngService1.pngProviderDependency.png


View solution in original post

10 REPLIES 10

Jessica_Wilson
Kilo Contributor

Angular Service Providers are essential in the design of a Service Portal, as they enable the definition and management of shared dependencies across various components. These providers allow for the creation of services that can be injected throughout the application, fostering reusability and modularity.
In a Service Portal, Angular Service Providers can be utilized to manage key functionalities like authentication, data retrieval, and user session management. By using these providers, you ensure that your Service Portal remains maintainable, scalable, and easy to test, with centralized logic that can be updated or modified without disrupting other parts of the application.

This method not only improves the efficiency of your Service Portal but also contributes to a more organized and cohesive codebase.