
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 09:25 PM
Hi All,
Scenario:
I have few widgets where in each widget it does multiplication of two numbers. So in each widget I call a function where it does the multiplication part. These individual widgets have some other functionality as well along with this multiplication.
So, I want to understand is there any way I can have this "multiplication of two numbers" function in a place (like a global function out of all widgets) defined and call that particular part when required.
Note: I need different widgets which have a common function for multiplication. So, is there any way to only have the function define at a separate place and call when required inside widget.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 11:36 PM
I figured out a way to resolve this issue:
Step 1: Go To Widget Angular Provider
Type: Service
Name: testService
Client Script:
function testService() {
this.showResult = function() {
return "Hi";
};
}
Step 2: Save
Step 3: Open widget where this Angular Provider needs to be called.
Step 4: Go to the Related List of the widget and add the service under "Angular Provider"
Step 5: Add below code in Client Controller of that Widget
api.controller = function($scope,testService) {
/* widget controller */
var c = this;
$scope.serviceCall = testService.showResult();
console.log("$scope.serviceCall: "+$scope.serviceCall);
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 12:33 AM
I tried the same way but getting below error:
$rootScope.add is not a function

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 12:45 AM
Please share the screenshot of client script of both widgets where you defined the funtion and calling it. so that i can help you debug

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 01:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 01:11 AM
on the second widget. please call it on demand. it will become issue if the first widget took time to load.
so call that function from when clicking a button that time it will surely work
<button ng-click="c.callAdd()"> Click Me <button>
c.callAdd=function(){
here callthe rootscope funtion
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 01:21 AM
Still getting same error on adding it inside button click:
$("#buttonAbc").click(function() {
$rootScope.callFunction(10,20);
});
Error:
$rootScope.callFunction is not a function