I came along this post researching on a memory leak we have in an angular 
app. Also your plunker is creating a Detached DOM Tree and leaves other 
data behind when you remove the element! That leads to a memory leak!

I am looking for a clean solution on how to remove the elements, which were 
added using $compile. A simple destroy on the scope is not doing the job 
well. It seems to be necessary to also remove watchers and listeners. 

Any solutions?

Am Freitag, 28. Juni 2013 03:08:06 UTC+2 schrieb Ian:
>
> Aha!. I missed the part where I needed to $compile(fragment)(scope) to 
> compile the fragment template and link it to the scope. 
>
> In the end, ngIf does what I want more than a custom directive could do. 
> (excepting the possibility of doing a comment)
>
> http://plnkr.co/edit/sV2V13?p=preview
>
> On Thursday, June 27, 2013 3:24:36 PM UTC-7, Dan Kang wrote:
>>
>> If you're manually appending dom elements, you need to also manually 
>> compile it - look into $compile service.
>>
>> For your use case, I'd look into ui-if in the Angular UI project or an 
>> equivalent (it's not hard to write a customized, specific version yourself)
>>
>> On Thursday, June 27, 2013 3:39:17 PM UTC-4, Ian wrote:
>>>
>>> That was a good start, but where it falls down is this:
>>>
>>> http://plnkr.co/edit/37aHor?p=preview
>>>
>>> I have a directive, but I don't want it to automatically add the 
>>> template content (because it would do this for every row which I don't 
>>> want).
>>>
>>> I can use element.append("some html") in the link function 
>>> conditionally, but these appended elements don't seem to trigger a 
>>> directive (nor can I use ng attributes in the append). 
>>>
>>> The goal is that when you click on the first column, a new template is 
>>> injected into the second column (this is a simplified case) and then 
>>> removed from any cells previously clicked. 
>>>
>>> On Thursday, June 27, 2013 12:23:58 AM UTC-7, Josh David Miller wrote:
>>>>
>>>> Hello!
>>>>
>>>> Sure. You just want a directive on or in the repeating element that 
>>>> adds a dom node on a particular event as a child of itself and can delete 
>>>> it in response to another. I can't create a plunker right now but 
>>>> basically 
>>>> you just need a template, to compile it, and then to call element.remove() 
>>>> when you're done. 
>>>>
>>>> Hopefully that helps.
>>>>
>>>> Josh
>>>> (Sent from my mobile)
>>>> I have an ng-repeat declaration for a table, and I'd like to add a 
>>>> "Drop down for more info" row that shows extra information about a row (or 
>>>> shows an editable form)
>>>>
>>>> But I don't want to include that template into the page for every row; 
>>>> I only want to do it when (say) an ng-click is called that "expands" the 
>>>> row. 
>>>>
>>>> Is there a way to add a template, and then remove it from the DOM when 
>>>> I'm done?
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "AngularJS" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/angular.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>  
>>>>  
>>>>  
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to