Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(Scope): expose transcluded and isolate scope info for batarang
Browse files Browse the repository at this point in the history
test($compile): add test for exposing transclude and isolate scope info to batarang
  • Loading branch information
btford committed Jan 30, 2013
1 parent e0295cf commit 649b892
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ function $CompileProvider($provide) {
(function(transcludeFn) {
return function(cloneFn) {
var transcludeScope = scope.$new();
transcludeScope.$$transcluded = true;

return transcludeFn(transcludeScope, cloneFn).
bind('$destroy', bind(transcludeScope, transcludeScope.$destroy));
Expand Down Expand Up @@ -725,6 +726,8 @@ function $CompileProvider($provide) {
lastValue,
parentGet, parentSet;

scope.$$isolateBindings[scopeName] = mode + attrName;

switch (mode) {

case '@': {
Expand Down
1 change: 1 addition & 0 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function $RootScopeProvider(){
this.$$destroyed = false;
this.$$asyncQueue = [];
this.$$listeners = {};
this.$$isolateBindings = {};
}

/**
Expand Down
38 changes: 38 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,21 @@ describe('$compile', function() {
compile('<div><span bad-declaration>');
}).toThrow('Invalid isolate scope definition for directive badDeclaration: xxx');
}));

it('should expose a $$isolateBindings property onto the scope', inject(function() {
compile('<div><span my-component>');

expect(typeof componentScope.$$isolateBindings).toBe('object');

expect(componentScope.$$isolateBindings.attr).toBe('@attr');
expect(componentScope.$$isolateBindings.attrAlias).toBe('@attr');
expect(componentScope.$$isolateBindings.ref).toBe('=ref');
expect(componentScope.$$isolateBindings.refAlias).toBe('=ref');
expect(componentScope.$$isolateBindings.reference).toBe('=reference');
expect(componentScope.$$isolateBindings.expr).toBe('&expr');
expect(componentScope.$$isolateBindings.exprAlias).toBe('&expr');

}));
});


Expand Down Expand Up @@ -2264,5 +2279,28 @@ describe('$compile', function() {

expect(element.text()).toBe('-->|x|');
}));


it('should add a $$transcluded property onto the transcluded scope', function() {
module(function() {
directive('trans', function() {
return {
transclude: true,
replace: true,
scope: true,
template: '<div><span>I:{{$$transcluded}}</span><div ng-transclude></div></div>'
};
});
});
inject(function(log, $rootScope, $compile) {
element = $compile('<div><div trans>T:{{$$transcluded}}</div></div>')
($rootScope);
$rootScope.$apply();
expect(jqLite(element.find('span')[0]).text()).toEqual('I:');
expect(jqLite(element.find('span')[1]).text()).toEqual('T:true');
});
});


});
});

0 comments on commit 649b892

Please sign in to comment.