This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +11
-13
lines changed
2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -735,9 +735,13 @@ function $CompileProvider($provide) {
735
735
scope [ scopeName ] = value ;
736
736
} ) ;
737
737
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
+ }
738
742
break ;
739
743
}
740
-
744
+
741
745
case '=' : {
742
746
parentGet = $parse ( attrs [ attrName ] ) ;
743
747
parentSet = parentGet . assign || function ( ) {
Original file line number Diff line number Diff line change @@ -1812,27 +1812,21 @@ describe('$compile', function() {
1812
1812
describe ( 'attribute' , function ( ) {
1813
1813
it ( 'should copy simple attribute' , inject ( function ( ) {
1814
1814
compile ( '<div><span my-component attr="some text">' ) ;
1815
- expect ( componentScope . attr ) . toEqual ( undefined ) ;
1816
- expect ( componentScope . attrAlias ) . toEqual ( undefined ) ;
1817
-
1818
- $rootScope . $apply ( ) ;
1819
1815
1820
1816
expect ( componentScope . attr ) . toEqual ( 'some text' ) ;
1821
1817
expect ( componentScope . attrAlias ) . toEqual ( 'some text' ) ;
1822
1818
expect ( componentScope . attrAlias ) . toEqual ( componentScope . attr ) ;
1823
1819
} ) ) ;
1824
1820
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 ( ) {
1831
1822
$rootScope . name = 'misko' ;
1832
- $rootScope . $apply ( ) ;
1833
-
1823
+ compile ( '<div><span my-component attr="hello {{name}}">' ) ;
1834
1824
expect ( componentScope . attr ) . toEqual ( 'hello misko' ) ;
1835
1825
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}}">' ) ;
1836
1830
1837
1831
$rootScope . name = 'igor' ;
1838
1832
$rootScope . $apply ( ) ;
You can’t perform that action at this time.
0 commit comments