Service Portal: How to call onClick() in Widgets

kutvaram
Tera Expert

Hi All,

How to call onClick() function in Widgets?

Below is my html code in widget:

< input type="file" id="uploadFile">

<button type="button" ng-click=foo()> Upload </button>

Below is my client script code in the widget:

function foo()

{

var f=document.getElementById("uploadFile");

if(f.value!=''

{

alert("File is selected");

}

else{

alert("Nothing is selected");

}

This is not working. Instead it is firing onload. How to achieve it when the "Upload" button is clicked?

Thoughts!

 

Best Regards,

Ram

 

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi ram,

 

You need to call the function in your client side of the widget as below. 

$scope.foo= function() {
//Put your code over here
};

 

Also, make sure that the $scope is also defined at the beginning of your client side.

//Refer the below line where the $scope is defined
function($scope,spUtil,$http,$timeout,$rootScope){
}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan

View solution in original post

3 REPLIES 3

Barrilito van D
Kilo Guru

Hi,

In the client script of the widget you should put in the function like this:

$scope.foo = function(){

//... your code...

}

ps. in the code you are showing you were missing an end brace "}" as well...  but do it as above, that is how it should be.

Regards.

Hi,

 

I tried the above mentioned step, but no luck. It is not working. 

 

Regards,

Ram

amlanpal
Kilo Sage

Hi ram,

 

You need to call the function in your client side of the widget as below. 

$scope.foo= function() {
//Put your code over here
};

 

Also, make sure that the $scope is also defined at the beginning of your client side.

//Refer the below line where the $scope is defined
function($scope,spUtil,$http,$timeout,$rootScope){
}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan