0

My view (a details itemId partial that lists img tags) is rendered from my controller. The number of img varies depending on the model pointed to by itemId. I need to change the div with which contains the ing tags to # of img x img width.

To do so, I need to make sure that my javascript in the view gets ran after the partial us rendered.

How to do that?

Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
  • You can create a directive and set a watch on the "model pointed to by itemId" and in there you can change the div width, maybe after a $timeout if the dom isn't in the state that you want it during the digest cycle. – JoseM Apr 17 '14 at 14:57

1 Answers1

0

You should not do js in the view, all js must be on angularjs end controllers, directives, etc. A better approach is to use a directive else you could wait for viewContentLoaded like this:

$scope.$on('$viewContentLoaded', function () {
    //Your js
}); 
Issam Zoli
  • 2,724
  • 1
  • 21
  • 35