Onclick widget help

Andre Jones
Tera Expert

Hello,

I'm working in the Service Portal and I have two widgets A page called CRT and another called CodeSource and I need the function of an end user to be able to click "Code Source" at the bottom corner of the page that then takes them to the popup page of the other widget modal

I have the following widget HTML that is 

<div class="footer">
<span>CUI//CDSource</span> <span>This is a Production System | <a href="=" onclick="codeSource">Code Source</a></span>
</div>

 

My client script is 

function codeSource (){

var userCodeSourceModal = new GlideModal("?id=privacy_act_statement", false, 837);
userCodeSourceModal.setSize(837,400);
userCodeSourceModal.render();
}

 

It's not working. Can someone point me to a better solution?

1 REPLY 1

-O-
Kilo Patron
Kilo Patron

In portal one has to use and is well advised to use AngularJS patterns/artifacts. Thus in place of onclick attribute, one has to use the ngClick - so called - directive:

 

<a href="" ng-click="codeSource">Code Source</a>

 

AngularJS will expect function codeSource to be a method of the current (widget's) scope; so it has to be defined as such (in the Client controller script, not Client script - there is no Client script in widgets/AngularJS):

 

api.controller = function ($scope) {
	/* widget controller */
	var c = this;

	$scope.codeSource = codeSource;

	function codeSource () {
		//...
	}
};

 

I don't think portal defines class GlideModal. One is expected to use AngularJS "friendly" services or providers - in this case spModal or $uibModal.

Look for examples on how to use those in existing widget Client controller scripts.