ng-include document fragments
If I do this:
<div ng-include="dialogs.html#sign-in"></div>
angular retrieves the dialog.html file, but includes the entire file, not just the #sign-in div. Same for templateUrl in directives.
This feature would be useful for applications that have a lot of small includes (e.g. for dialogs), but don't want to inline them on the main page (which slows down loading of the first page) or have them retrieved one by one.
+1 for this one
+1
The ng-include should provide same flexibility as the one of JQuery load() function:
http://api.jquery.com/load/
Ex:
jQuery('#myPanel').empty();
jQuery('#myPanel').load('fragments/myFragment.html #interstingDiv', function() { ... ... });
+1
I like this idea.
+1
It would be usefull.
+1
If you are using ng-grid and cell rendering templates it would be nice to have them all in one file rather than a bunch of little files (I prefer to manage them in html vs js)
+1 that it would be ideal for ngInclude to be a drop-in alternative to jQuery.load()
I have two motivations for this:
(1) My motivation is that I have projects which I am retrofitting with Angular, and these projects will sometimes use jQuery.load() with selectors.
(2) I have the same motivation as the OP. I am aware that pre-warming the templateCache is a workaround for this, but it would still be nice to have the option to load fragments anyways.
I've proposed a patch that uses Angular's .find() function and is implemented identically to jQuery.load(). It retains full backwards compatibility with ngInclude. The only caveat is this: the types of selectors that can be used are limited to Angular's .find(). This means that if using Angular alone, it will be limited to selecting only element names (e.g. div or span) - to use full selectors, you'll need to include jQuery, and then #foo or .stuff > div > div >div can be used, i.e. for example:
<div ng-include="'dialogs.html div'"></div> <!-- pure Angular (no jQuery) -->
<div ng-include="'dialogs.html #sign-in'"></div> <!-- jQuery+Angular -->
<div ng-include="'dialogs.html #sign-in .stuff > div'"></div> <!-- jQuery+Angular -->
The AngularUI project now offers uiInclude. uiInclude is identical to the Angular 1.0.x ngInclude (hence, no animation) with a new extra fragment attribute. It works like this:
<ui-include src="'url/to/partial/file'" fragment="'#id-to-fragment'"></ui-include>
When writing your Angular app, the following extra two lines will enable you to use uiInclude:
<script src="include.js"></script>
app = angular.module('myApp', ['ui.include']);
Note that jQuery is required for full selector support, otherwise it falls back to jqLite which supports very limited selectors. Also note that both src and fragment are Angular expressions, and therefore string literals must be quoted. I'd be all in favor of moving this capability over to Angular if the Angular devs think it is appropriate.
Based on discussion in https://github.com/angular/angular.js/pull/3151 I think that we can close this one.