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

Commit 2ed5308

Browse files
petebacondarwinmhevery
authored andcommitted
fix(compile): Interpolate @ locals before the link function runs
Do a one-off interpolation of @ locals to ensure that the link fn receives attributes that are already interpolated.
1 parent 0af1720 commit 2ed5308

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/ng/compile.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,13 @@ function $CompileProvider($provide) {
735735
scope[scopeName] = value;
736736
});
737737
attrs.$$observers[attrName].$$scope = parentScope;
738+
if( attrs[attrName] ) {
739+
// If the attribute has been provided then we trigger an interpolation to ensure the value is there for use in the link fn
740+
scope[scopeName] = $interpolate(attrs[attrName])(parentScope);
741+
}
738742
break;
739743
}
740-
744+
741745
case '=': {
742746
parentGet = $parse(attrs[attrName]);
743747
parentSet = parentGet.assign || function() {

test/ng/compileSpec.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1812,27 +1812,21 @@ describe('$compile', function() {
18121812
describe('attribute', function() {
18131813
it('should copy simple attribute', inject(function() {
18141814
compile('<div><span my-component attr="some text">');
1815-
expect(componentScope.attr).toEqual(undefined);
1816-
expect(componentScope.attrAlias).toEqual(undefined);
1817-
1818-
$rootScope.$apply();
18191815

18201816
expect(componentScope.attr).toEqual('some text');
18211817
expect(componentScope.attrAlias).toEqual('some text');
18221818
expect(componentScope.attrAlias).toEqual(componentScope.attr);
18231819
}));
18241820

1825-
1826-
it('should update when interpolated attribute updates', inject(function() {
1827-
compile('<div><span my-component attr="hello {{name}}">');
1828-
expect(componentScope.attr).toEqual(undefined);
1829-
expect(componentScope.attrAlias).toEqual(undefined);
1830-
1821+
it('should set up the interpolation before it reaches the link function', inject(function() {
18311822
$rootScope.name = 'misko';
1832-
$rootScope.$apply();
1833-
1823+
compile('<div><span my-component attr="hello {{name}}">');
18341824
expect(componentScope.attr).toEqual('hello misko');
18351825
expect(componentScope.attrAlias).toEqual('hello misko');
1826+
}));
1827+
1828+
it('should update when interpolated attribute updates', inject(function() {
1829+
compile('<div><span my-component attr="hello {{name}}">');
18361830

18371831
$rootScope.name = 'igor';
18381832
$rootScope.$apply();

0 commit comments

Comments
 (0)