Service Portal widget event handler

Tommy Jensen
Giga Guru

I want to add an event handler for when the form has been loaded so I added following in the Client script in a new widget. 

$rootScope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
		console.log('In spModel.gForm.initialized');   
    });

I have also tried

$scope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
		console.log('In spModel.gForm.initialized');   
    });

But nothing happens what the pages is loaded.

The weird thing is that I have another widget (more complex one with both client and server scripts) where I use the exact same code and in that widget it works fine.

Of course both $scope and $rootScope is injected with

function($scope, $rootScope)

 

6 REPLIES 6

Frank Silveira1
Kilo Expert

Hello there,

 

See if this works for you:

 

$rootScope.$on('spModel.gForm.rendered', function (e, gFormInstance)

David Arbour
Tera Guru

You should be listening for 'spModel.gForm.rendered' on $rootScope, not $scope.

$rootScope.$on('spModel.gForm.rendered', function (event, g_form) {
    console.log('spModel.gForm.rendered fired');
    // you can safely use g_form as you would in a client script
});