aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--regression/filter_repeater.html1
-rw-r--r--regression/ng_include_this.html9
-rw-r--r--regression/ng_include_this.partial1
-rw-r--r--src/widgets.js10
-rw-r--r--test/widgetsSpec.js11
5 files changed, 30 insertions, 2 deletions
diff --git a/regression/filter_repeater.html b/regression/filter_repeater.html
index 202a6311..4160fc6a 100644
--- a/regression/filter_repeater.html
+++ b/regression/filter_repeater.html
@@ -2,7 +2,6 @@
<html xmlns:ng="http://angularjs.org">
<head>
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
- </script>
</head>
<body ng:init="$window.$root = this; data = [{foo: 'foo'},{bar: 'bar'}]">
<p>This is a demo of a potential bug in angular.</p>
diff --git a/regression/ng_include_this.html b/regression/ng_include_this.html
new file mode 100644
index 00000000..3138ed07
--- /dev/null
+++ b/regression/ng_include_this.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html xmlns:ng="http://angularjs.org">
+<head>
+ <script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
+</head>
+<body ng:init="$window.$root = this; data = [{foo: 'foo'},{bar: 'bar'}]">
+ <ng:include src="'ng_include_this.partial'" scope="this"/>
+</body>
+</html> \ No newline at end of file
diff --git a/regression/ng_include_this.partial b/regression/ng_include_this.partial
new file mode 100644
index 00000000..a4673196
--- /dev/null
+++ b/regression/ng_include_this.partial
@@ -0,0 +1 @@
+included HTML. eval count: {{c=c+1}} \ No newline at end of file
diff --git a/src/widgets.js b/src/widgets.js
index 877f4a72..34cc258a 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -256,11 +256,19 @@ angularWidget('ng:include', function(element){
return extend(function(xhr, element){
var scope = this, childScope;
var changeCounter = 0;
+ var preventRecursion = false;
function incrementChange(){ changeCounter++;}
this.$watch(srcExp, incrementChange);
this.$watch(scopeExp, incrementChange);
scope.$onEval(function(){
- if (childScope) childScope.$eval();
+ if (childScope && !preventRecursion) {
+ preventRecursion = true;
+ try {
+ childScope.$eval();
+ } finally {
+ preventRecursion = false;
+ }
+ }
});
this.$watch(function(){return changeCounter;}, function(){
var src = this.$eval(srcExp),
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index df0941c0..2d1aef1a 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -497,6 +497,17 @@ describe("widget", function(){
expect(element.text()).toEqual('');
});
+
+ it('should allow this for scope', function(){
+ var element = jqLite('<ng:include src="url" scope="this"></ng:include>');
+ var scope = angular.compile(element);
+ scope.url = 'myUrl';
+ scope.$inject('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'};
+ scope.$init();
+ // This should not be 4, but to fix this properly
+ // we need to have real events on the scopes.
+ expect(element.text()).toEqual('4');
+ });
});
describe('a', function() {