Lazy ng:include?

1,095 views
Skip to first unread message

Eric Jain

unread,
Feb 14, 2012, 2:05:59 PM2/14/12
to AngularJS
Is it possible to load external fragments only when they are made
visible? This would be useful for loading the contents of dialogs etc
without slowing down the initial page load.

Misko Hevery

unread,
Feb 15, 2012, 1:12:57 AM2/15/12
to ang...@googlegroups.com
I am assuming that you are putting ng:include into ng:show/hide.

Use ng:switch instead of ng:show and you will have the desired effect


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Eric Jain

unread,
Feb 15, 2012, 3:34:29 AM2/15/12
to ang...@googlegroups.com
On Tue, Feb 14, 2012 at 22:12, Misko Hevery <mi...@hevery.com> wrote:
> I am assuming that you are putting ng:include into ng:show/hide.
>
> Use ng:switch instead of ng:show and you will have the desired effect

I'm using bootstrap modal to open dialogs. I suppose I could instead
have the dialogs inside an ng:switch and set a dialogId property on
the main controller to show/hide a dialog...

Misko Hevery

unread,
Feb 15, 2012, 3:27:34 PM2/15/12
to ang...@googlegroups.com
Have a look at the new compiler which will be released soon: 

chri...@googlemail.com

unread,
Nov 27, 2012, 4:08:32 AM11/27/12
to ang...@googlegroups.com, mi...@hevery.com
Hi all,

I tried to implement lazy loading using ng-switch + ng-include for tabs. The problem is that the UI state of a tab (filled out forms, etc) is not being saved when switching them.
Can you see a possibility to implement it in a way that the lazy loaded part of the dom is just hidden and then shown again, so that it keeps it's state?

I posted a detailed description here: https://groups.google.com/forum/#!searchin/angular/lazy$20ng-include/angular/egiNF2hP0yE/TvW4hJdqPJEJ

Thanks,
Chris

chri...@googlemail.com

unread,
Nov 27, 2012, 7:49:52 AM11/27/12
to ang...@googlegroups.com, mi...@hevery.com, chri...@googlemail.com
Hi all,

I found a solution for my problem, the trick is to use ng-include with "src" property not initially set. When you want the lazy loading to occur you set it to the corresponding value.
You can find more details and some sample code in the related post. https://groups.google.com/forum/#!searchin/angular/lazy$20ng-include/angular/egiNF2hP0yE/TvW4hJdqPJEJ

Regards,
Chris
Reply all
Reply to author
Forward
0 new messages