Home Ask Login Register

Developers Planet

Your answer is one click away!

FaithReaper February 2016

Calculating data and render them after fetching all data from server side; $(window).load() no luck

I have a <s:iterator> to fetch all data from server side and display them in page:

<s:iterator id="lstActividades" value="impDesLst">
        <td><input ng-change="actualizarDias();" type="text" class="form-control" name="produccionForm.minutosL<s:property value="%{actividad.idActividad}" />" id="produccionForm.minutosL<s:property value="%{actividad.idActividad}" />" ng_model="minutosL<s:property value="%{actividad.idActividad}" />" ng-init="minutosL<s:property value="%{actividad.idActividad}" />='<s:property value="%{producciones[0].minutos}" />'" /></td>

Note that it has ng-change=actualizarDias() which calculate all data in a row and render the result. It works well when the number changes.

However, I want to get the result when the page is loaded for the first time. Now the result field is blank, but if we press F5 or change one number, all result come out correctly.

As I can see, if I want to use jQuery function, they must be defined out of Angular controller, so I tried:

  • define $(window).load(function(){}); out of Angular controller, like this:

    $(window).load(function(){ angular.element(document).scope().actualizarDias(); });

  • define following function inside Angular controller:

    $scope.$on('$viewContentLoaded', function ($evt) { $scope.actualizarDias(); });//not working

  • define following function also inside Augular controller:

    setTimeout(function(){ $scope.$apply(function() { $(window).load(function(){ $scope.actualizarDias(); }); }); });//not working

To no avail.

My script is in an isolated jsp file with following structure:



DoctorMick February 2016

You can just call the function in the main body of your controller to make sure it is executed when the controller is created:

function MyController() {
    $scope.actualizarDias = function(){


Although as it stands that will probably still fail as you've got a lot of view specific code in your controller which is a really bad idea. You should look to change the structure of your code so that the data in the table is loaded in to your controller and bind to that rather than having your controller iterating over a table.

Post Status

Asked in February 2016
Viewed 2,213 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life