From 17ee0f031ac4a37bf9a1dc8c87ffac4bd164d1cc Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Wed, 19 Jan 2011 21:47:14 -0800
Subject: fix ng:include issue introduced by a5eb3ed1
---
src/widgets.js | 7 ++++++-
test/widgetsSpec.js | 19 ++++++++++++++++++-
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/widgets.js b/src/widgets.js
index 4585629a..1ab8a2c9 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -635,7 +635,12 @@ angularWidget('ng:include', function(element){
if (src) {
xhr('GET', src, function(code, 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);
childScope.$init();
scope.$eval(onloadExp);
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 27c5cb82..6ec056ca 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -609,7 +609,24 @@ describe("widget", 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('');
+ 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('');
var scope = angular.compile(element);
scope.childScope = createScope();
--
cgit v1.2.3