javascript - Calculating data and render them after fetching all data from server side; $(window).load() no luck -
i have <s:iterator>
fetch data server side , display them in page:
<s:iterator id="lstactividades" value="impdeslst"> <tr> <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 has ng-change=actualizardias()
calculate data in row , render result. works when number changes.
however, want result when page loaded first time. result field blank, if press f5 or change 1 number, result come out correctly.
as can see, if want use jquery function, must defined out of angular controller, tried:
define
$(window).load(function(){});
out of angular controller, 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 inside augular controller:
settimeout(function(){ $scope.$apply(function() { $(window).load(function(){ $scope.actualizardias(); }); }); });//not working
to no avail.
my script in isolated jsp
file following structure:
<% response.setheader("cache-control","no-cache"); response.setheader("pragma","no-cache"); response.setdateheader ("expires", -1); %> <%@ taglib prefix="s" uri="/struts-tags" %> <script type="text/javascript"> angular.module('myapp').controller('myctrl', function($scope, $modal, $window, $http, proccessformservice) { $scope.function1 = function() {...}; $scope.function2 = function() {....}; $scope.actualizardias() = function() {...}; }
now, how can load result when enter page first time?
my calculation function is:
$scope.actualizardias = function(){ tabla = document.getelementbyid('tablaproducciones').children[1]; $scope.impl=""; $scope.minutostotalesl=""; $scope.minutostotaleslformat=""; (var i=1; i<tabla.children.length*2; i++){ if (i%2!=0) { var inputl = tabla.childnodes[i].cells[2].children[0].value; var inputact = tabla.childnodes[i].cells[0].innerhtml; if($scope.impl=="" || $scope.impl==undefined){ $scope.impl=inputact + "-" + inputl; } else { $scope.impl+=";" + inputact + "-" + inputl; } if (!isnan(inputl) && inputl>0){ if ($scope.minutostotalesl=='' || $scope.minutostotalesl==undefined){ $scope.minutostotalesl=inputl; } else { $scope.minutostotalesl=parseint($scope.minutostotalesl) + parseint(inputl); } $scope.minutostotaleslformat = $scope.minutosahoras($scope.minutostotalesl); } } } }
you can call function in main body of controller make sure executed when controller created:
function mycontroller() { $scope.actualizardias = function(){ ... } $scope.actualizardias(); }
although stands still fail you've got lot of view specific code in controller bad idea. should change structure of code data in table loaded in controller , bind rather having controller iterating on table.
Comments
Post a Comment