mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-15 10:13:10 +00:00
fix ng:include issue introduced by a5eb3ed1
This commit is contained in:
parent
10646c9f6f
commit
17ee0f031a
2 changed files with 24 additions and 2 deletions
|
|
@ -635,7 +635,12 @@ angularWidget('ng:include', function(element){
|
||||||
if (src) {
|
if (src) {
|
||||||
xhr('GET', src, function(code, response){
|
xhr('GET', src, function(code, response){
|
||||||
element.html(response);
|
element.html(response);
|
||||||
childScope = useScope || createScope(scope);
|
if (useScope) {
|
||||||
|
childScope = useScope;
|
||||||
|
} else {
|
||||||
|
childScope = createScope(scope);
|
||||||
|
scope.$onEval(childScope.$eval);
|
||||||
|
}
|
||||||
compiler.compile(element)(element, childScope);
|
compiler.compile(element)(element, childScope);
|
||||||
childScope.$init();
|
childScope.$init();
|
||||||
scope.$eval(onloadExp);
|
scope.$eval(onloadExp);
|
||||||
|
|
|
||||||
|
|
@ -609,7 +609,24 @@ describe("widget", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ng:include', function(){
|
describe('ng:include', function(){
|
||||||
it('should include on external file', function() {
|
it('should include on external file and create a new child scope', function() {
|
||||||
|
var element = jqLite('<ng:include src="url"></ng:include>');
|
||||||
|
var scope = angular.compile(element);
|
||||||
|
scope.counter = 0;
|
||||||
|
scope.url = 'myUrl';
|
||||||
|
scope.$service('$xhr.cache').data.myUrl = {value:'{{counter = counter + 1}}'};
|
||||||
|
scope.$init();
|
||||||
|
scope.$service('$browser').defer.flush();
|
||||||
|
expect(element.text()).toEqual('2');
|
||||||
|
|
||||||
|
//should also propagate evals to the child scope
|
||||||
|
scope.$eval();
|
||||||
|
expect(element.text()).toEqual('3');
|
||||||
|
|
||||||
|
dealoc(scope);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should include on external file and use an existing child scope', function() {
|
||||||
var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
|
var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
|
||||||
var scope = angular.compile(element);
|
var scope = angular.compile(element);
|
||||||
scope.childScope = createScope();
|
scope.childScope = createScope();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue