Surprising behavior (and regression) when $compiling ngInclude directives #4505
Description
$compiling a naked ng-include directive fails in 1.2.0-rc.*, although it has worked in earlier versions. In a test along the following lines:
describe('Integration',function(){
var app;
beforeEach(module('app', 'views/main.html'));
beforeEach(inject(function($compile, $rootScope){
app = $compile(
'<ng-include src="\'views/main.html\'"></ng-include>'
)($rootScope.$new());
$rootScope.$digest();
console.log(angular.version);
console.log(app);
}));
it('should run angular', function(){
expect(app.find('h1').text()).toBe('Super2');
});
});
where views/main.html is:
<h1>Super{{1+1}}</h1>
I get the following results, for v1.0.5, which works fine:
LOG: Object{full: '1.0.5', major: 1, minor: 0, dot: 5, codeName: 'flatulent-propulsion'}
LOG: {0: <ng-include src="'views/main.html'" class="ng-scope"><h1 class="ng-scope ng-binding">Super2</h1>
and the test passes, but for 1.2.0.rc-*:
LOG: Object{full: '1.2.0-rc.3', major: 1, minor: 2, dot: 0, codeName: 'ferocious-twitch'}
LOG: {0: <!-- ngInclude: undefined -->, length: 1}
the test fails, with the actual result being ''
instead of Super2
. Interestingly, the code works just fine in both versions if you surround the <ng-include>
directive with a naked <div>
.
If this is an intended regression, I haven't seen any documentation (which doesn't mean its not there). Can you explain the reasons why this directive fails in current versions, while others do not, so I can anticipate the problem? Or should I simply make a routine practice of surrounding all code delivered to compile with a naked div?