@@ -2359,7 +2359,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23592359
23602360 function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
23612361 var i , ii , linkFn , isolateScope , controllerScope , elementControllers , transcludeFn , $element ,
2362- attrs , removeScopeBindingWatches , removeControllerBindingWatches ;
2362+ attrs , scopeBindingInfo ;
23632363
23642364 if ( compileNode === linkNode ) {
23652365 attrs = templateAttrs ;
@@ -2398,11 +2398,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23982398 compile . $$addScopeClass ( $element , true ) ;
23992399 isolateScope . $$isolateBindings =
24002400 newIsolateScopeDirective . $$isolateBindings ;
2401- removeScopeBindingWatches = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2401+ scopeBindingInfo = initializeDirectiveBindings ( scope , attrs , isolateScope ,
24022402 isolateScope . $$isolateBindings ,
24032403 newIsolateScopeDirective ) ;
2404- if ( removeScopeBindingWatches ) {
2405- isolateScope . $on ( '$destroy' , removeScopeBindingWatches ) ;
2404+ if ( scopeBindingInfo . removeWatches ) {
2405+ isolateScope . $on ( '$destroy' , scopeBindingInfo . removeWatches ) ;
24062406 }
24072407 }
24082408
@@ -2413,8 +2413,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24132413 var bindings = controllerDirective . $$bindings . bindToController ;
24142414
24152415 if ( controller . identifier && bindings ) {
2416- removeControllerBindingWatches =
2416+ controller . bindingInfo =
24172417 initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2418+ } else {
2419+ controller . bindingInfo = { } ;
24182420 }
24192421
24202422 var controllerResult = controller ( ) ;
@@ -2423,8 +2425,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24232425 // from setupControllers
24242426 controller . instance = controllerResult ;
24252427 $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2426- removeControllerBindingWatches && removeControllerBindingWatches ( ) ;
2427- removeControllerBindingWatches =
2428+ controller . bindingInfo . removeWatches && controller . bindingInfo . removeWatches ( ) ;
2429+ controller . bindingInfo =
24282430 initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
24292431 }
24302432 }
@@ -2440,6 +2442,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24402442 // Handle the init and destroy lifecycle hooks on all controllers that have them
24412443 forEach ( elementControllers , function ( controller ) {
24422444 var controllerInstance = controller . instance ;
2445+ if ( isFunction ( controllerInstance . $onChanges ) ) {
2446+ controllerInstance . $onChanges ( controller . bindingInfo . initialChanges ) ;
2447+ }
24432448 if ( isFunction ( controllerInstance . $onInit ) ) {
24442449 controllerInstance . $onInit ( ) ;
24452450 }
@@ -3086,6 +3091,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
30863091 // only occurs for isolate scopes and new scopes with controllerAs.
30873092 function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
30883093 var removeWatchCollection = [ ] ;
3094+ var initialChanges = { } ;
30893095 var changes ;
30903096 forEach ( bindings , function initializeBinding ( definition , scopeName ) {
30913097 var attrName = definition . attrName ,
@@ -3118,7 +3124,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
31183124 // the value to boolean rather than a string, so we special case this situation
31193125 destination [ scopeName ] = lastValue ;
31203126 }
3121- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3127+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
31223128 break ;
31233129
31243130 case '=' :
@@ -3174,7 +3180,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
31743180 parentGet = $parse ( attrs [ attrName ] ) ;
31753181
31763182 destination [ scopeName ] = parentGet ( scope ) ;
3177- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3183+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
31783184
31793185 removeWatch = scope . $watch ( parentGet , function parentValueWatchAction ( newParentValue ) {
31803186 var oldValue = destination [ scopeName ] ;
@@ -3226,9 +3232,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
32263232 changes = undefined ;
32273233 }
32283234
3229- return removeWatchCollection . length && function removeWatches ( ) {
3230- for ( var i = 0 , ii = removeWatchCollection . length ; i < ii ; ++ i ) {
3231- removeWatchCollection [ i ] ( ) ;
3235+ return {
3236+ initialChanges : initialChanges ,
3237+ removeWatches : removeWatchCollection . length && function removeWatches ( ) {
3238+ for ( var i = 0 , ii = removeWatchCollection . length ; i < ii ; ++ i ) {
3239+ removeWatchCollection [ i ] ( ) ;
3240+ }
32323241 }
32333242 } ;
32343243 }
0 commit comments