0

Suppose I have this template

<span>{{scopeVariable}}</span>

And suppose somewhere in the angular scope I modify the variable scopeVariable, which will make it display on the dom...Suppose the span with class lol is initially hidden (and I'd like it to remain that way) so I then execute a jquery statement to display it

$scope.scopeVariable = '<span class="lol">A whole bunch of stuff</span>';
$('.lol').show();

The problem is that the javascript will execute before the entire scopeVariable placeholder on the dom is replaced with the variable value hence span '.lol' remains hidden...

My question is, how do I get angular to detect when the lol span will finish rendering on the placeholder, so that I can then execute the show() function to make it show properly?

pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
  • Why not just do the same thing without the jQuery? For example with ngStyle or ngClass. Also, it's very bad practice to do DOM manipulation from your controller, which you don't *say* that you're doing, but it *sounds* like you're doing. If you elaborate a little more, I can provide a more complete answer. – Josh David Miller Mar 29 '13 at 22:06
  • I know I can do it without jQuery. I'm curious if there is a way to do it using this methodology in general (ie. having angular detecting when the variable has been fully rendered) – pillarOfLight Mar 29 '13 at 22:12
  • This is generally not a good idea as this isn't how AngularJS is supposed to work. I'm not aware of any good workarounds nor of any cases where you'd want one. This SO question might help if you're newer to AngularJS and coming from jQuery: http://stackoverflow.com/q/14994391/259038 – Josh David Miller Mar 29 '13 at 22:17
  • 1
    can also use `ng-show` and `ng-hide` which are set based on scope `expression`..see docs. Need to get out of `jQuery thinking` mode. My strength is jQuery, and when using angular, I don't even include it when starting a project up. I add it later for plugins and to improve `jQlite` capabilities, but starting without it included in page helps gear your mind to using angular features – charlietfl Mar 30 '13 at 00:42

0 Answers0