$compile and ng:repeat

1,459 views
Skip to first unread message

Joshua Gruber

unread,
Feb 24, 2012, 3:42:32 PM2/24/12
to AngularJS
I'm having trouble either with the documentation or the implementation
of $compile. If it's the documentation, I'll submit a patch when I've
fully grokked it :) Here's the issue:

I'm trying to include Angular functionality in a dynamically attached
element. (tipsy and tooltipsy both animate using this functionality,
e.g.) I'm using $compile, which works partially. ng:click appears to
operate in the appropriate scope, but ng:repeat isn't operating as I
would hope--it thinks its compiled, but it doesn't seem to access the
controller's model. From the docs, it seemed like I needed to run
$apply, but it doesn't help when I run it in the current scope (I can
run it in ActionA with no effect. If I run it right after $compile,
there's a digest in progress.)
http://jsfiddle.net/z7a58/4/

Here's an attempt to save a reference to the element and run $apply on
the scope, but when I do that it tells me there's a digest already in
progress:
http://jsfiddle.net/z7a58/5/

Is this me misunderstanding $compile, scope, ng:controller, or
something else?

Vojta Jina

unread,
Feb 24, 2012, 4:05:20 PM2/24/12
to ang...@googlegroups.com
You got typo in the second ng:repeat, if you change items -> item, the repeater will work, but not with tipsy...
That's because you are calling tipsy to early, before ng:repeater creates the nodes, you should not touch dom elements from the controller.
Move it to directive.

V.

Joshua Gruber

unread,
Feb 24, 2012, 6:14:53 PM2/24/12
to AngularJS
That would work. Here's another way:
http://jsfiddle.net/z7a58/10/
complete with fixed typo. Thanks :)

It turned out that even having the tipsy called after all the
rendering didn't help, because the $compile() was what was breaking
it. Here it is, with tipsy handled late and compile only run after a
click... it's only when you $compile() it that the repeater breaks
(but, oddly, the ng:click directive doesn't break.)
http://jsfiddle.net/z7a58/12/

So, is this inconsistent behavior in $compile() an issue, or should I
update the $compile() documentation to indicate that it should not be
run on elements that have already been processed by the angular HTML
compiler?

Vojta Jina

unread,
Feb 26, 2012, 12:59:56 AM2/26/12
to ang...@googlegroups.com
This is Angular way...
http://jsfiddle.net/vojtajina/z7a58/15/

V.
Reply all
Reply to author
Forward
0 new messages