- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 02:29 PM
Hi community,
I'm looking for the best way to declare a shared constant (in my case, an Array) and use it within every widgets (client script) of my Service Portal.
I found an angular solution but I'm not sure it's possible in sp :
// Storing a single constant value
var app = angular.module('myApp', []);
app.constant('appName', 'My App');
// Now we inject our constant value into a test controller
app.controller('TestCtrl', ['appName', function TestCtrl(appName) {
console.log(appName);
}]);
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 06:05 AM
Hi,
You can add your constant directly to the Service Portal's main module in your portal's theme JS Include like this:
angular.module("sn.$sp").constant("appName", "My App");
After that appName becomes available for injection in your application. You can use it in all controllers and other functions that support dependency injection in Angular.
Regards,
Iurii
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 02:58 PM
Hi,
1. You can use rootScope to communicate between widgets, below reference links can be helpful :
https://www.youtube.com/watch?v=Wcz0PixUneQ&index=7&list=PL3rNcyAiDYK3YiwkTj8OUSs_FRz-YSIw2
2. You can also go for HTML5 localStorage option (not best practise)
Regards,
Chirag Bagdai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 04:46 AM
Thanks you Chirag.
I agree with you. The rootscope allows to discuss with other widgets in real time.
For my part, I'm looking for a way to declare global constants for the portal and not in a particular widget. Widgets must be independent.
I have develop a script and a dependency with the widget for shared functions and it works fine.
Now, I would like to use the same thing to declare constants and variables but I don't know how.
Any idea ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2017 01:22 PM
I am not sure about angular but you can try to declare constant/global variable in UI script and include that UI script in your portal theme (JS Include).
I hope this helps.
Regards,
Chirag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 06:05 AM
Hi,
You can add your constant directly to the Service Portal's main module in your portal's theme JS Include like this:
angular.module("sn.$sp").constant("appName", "My App");
After that appName becomes available for injection in your application. You can use it in all controllers and other functions that support dependency injection in Angular.
Regards,
Iurii