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

Commit

Permalink
fix(compile): Interpolate @ locals before the link function runs
Browse files Browse the repository at this point in the history
Do a one-off interpolation of @ locals to ensure that the link fn receives attributes that are already interpolated.
  • Loading branch information
petebacondarwin authored and mhevery committed Feb 15, 2013
1 parent 0af1720 commit 2ed5308
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,13 @@ function $CompileProvider($provide) {
scope[scopeName] = value;
});
attrs.$$observers[attrName].$$scope = parentScope;
if( attrs[attrName] ) {
// If the attribute has been provided then we trigger an interpolation to ensure the value is there for use in the link fn
scope[scopeName] = $interpolate(attrs[attrName])(parentScope);
}
break;
}

case '=': {
parentGet = $parse(attrs[attrName]);
parentSet = parentGet.assign || function() {
Expand Down
18 changes: 6 additions & 12 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,27 +1812,21 @@ describe('$compile', function() {
describe('attribute', function() {
it('should copy simple attribute', inject(function() {
compile('<div><span my-component attr="some text">');
expect(componentScope.attr).toEqual(undefined);
expect(componentScope.attrAlias).toEqual(undefined);

$rootScope.$apply();

expect(componentScope.attr).toEqual('some text');
expect(componentScope.attrAlias).toEqual('some text');
expect(componentScope.attrAlias).toEqual(componentScope.attr);
}));


it('should update when interpolated attribute updates', inject(function() {
compile('<div><span my-component attr="hello {{name}}">');
expect(componentScope.attr).toEqual(undefined);
expect(componentScope.attrAlias).toEqual(undefined);

it('should set up the interpolation before it reaches the link function', inject(function() {
$rootScope.name = 'misko';
$rootScope.$apply();

compile('<div><span my-component attr="hello {{name}}">');
expect(componentScope.attr).toEqual('hello misko');
expect(componentScope.attrAlias).toEqual('hello misko');
}));

it('should update when interpolated attribute updates', inject(function() {
compile('<div><span my-component attr="hello {{name}}">');

$rootScope.name = 'igor';
$rootScope.$apply();
Expand Down

0 comments on commit 2ed5308

Please sign in to comment.