aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2010-11-16 11:31:41 -0800
committerIgor Minar2010-11-16 11:35:43 -0800
commita130bb899d790dc11393276b34d59b2ddd5cc680 (patch)
tree76c7bc4135933b0a6a1cbc1444d52857b139ebb8
parentcc749760fd59418433de5a055d1ca401f7500444 (diff)
downloadangular.js-a130bb899d790dc11393276b34d59b2ddd5cc680.tar.bz2
add onload attribute to ng:include
-rw-r--r--src/widgets.js8
-rw-r--r--test/widgetsSpec.js13
2 files changed, 19 insertions, 2 deletions
diff --git a/src/widgets.js b/src/widgets.js
index 0ebdd1d5..887b31ac 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -494,6 +494,7 @@ angularWidget('option', function(){
*
* @param {string} src expression evaluating to URL.
* @param {Scope=} [scope=new_child_scope] expression evaluating to angular.scope
+ * @param {string=} onload Expression to evaluate when a new partial is loaded.
*
* @example
* <select name="url">
@@ -521,7 +522,8 @@ angularWidget('option', function(){
angularWidget('ng:include', function(element){
var compiler = this,
srcExp = element.attr("src"),
- scopeExp = element.attr("scope") || '';
+ scopeExp = element.attr("scope") || '',
+ onloadExp = element[0].getAttribute('onload') || ''; //workaround for jquery bug #7537
if (element[0]['ng:compiled']) {
this.descend(true);
this.directives(true);
@@ -546,13 +548,15 @@ angularWidget('ng:include', function(element){
});
this.$watch(function(){return changeCounter;}, function(){
var src = this.$eval(srcExp),
- useScope = this.$eval(scopeExp);
+ useScope = this.$eval(scopeExp);
+
if (src) {
xhr('GET', src, function(code, response){
element.html(response);
childScope = useScope || createScope(scope);
compiler.compile(element)(element, childScope);
childScope.$init();
+ scope.$eval(onloadExp);
});
} else {
childScope = null;
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 34ea6b1d..03eb3acd 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -532,6 +532,19 @@ describe("widget", function(){
// we need to have real events on the scopes.
expect(element.text()).toEqual('4');
});
+
+ it('should evaluate onload expression when a partial is loaded', function() {
+ var element = jqLite('<ng:include src="url" onload="loaded = true"></ng:include>');
+ var scope = angular.compile(element);
+
+ expect(scope.loaded).not.toBeDefined();
+
+ scope.url = 'myUrl';
+ scope.$inject('$xhr.cache').data.myUrl = {value:'my partial'};
+ scope.$init();
+ expect(element.text()).toEqual('my partial');
+ expect(scope.loaded).toBe(true);
+ });
});
describe('a', function() {