@@ -2359,7 +2359,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2359
2359
2360
2360
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
2361
2361
var i , ii , linkFn , isolateScope , controllerScope , elementControllers , transcludeFn , $element ,
2362
- attrs , removeScopeBindingWatches , removeControllerBindingWatches ;
2362
+ attrs , scopeBindingInfo ;
2363
2363
2364
2364
if ( compileNode === linkNode ) {
2365
2365
attrs = templateAttrs ;
@@ -2398,11 +2398,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2398
2398
compile . $$addScopeClass ( $element , true ) ;
2399
2399
isolateScope . $$isolateBindings =
2400
2400
newIsolateScopeDirective . $$isolateBindings ;
2401
- removeScopeBindingWatches = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2401
+ scopeBindingInfo = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2402
2402
isolateScope . $$isolateBindings ,
2403
2403
newIsolateScopeDirective ) ;
2404
- if ( removeScopeBindingWatches ) {
2405
- isolateScope . $on ( '$destroy' , removeScopeBindingWatches ) ;
2404
+ if ( scopeBindingInfo . removeWatches ) {
2405
+ isolateScope . $on ( '$destroy' , scopeBindingInfo . removeWatches ) ;
2406
2406
}
2407
2407
}
2408
2408
@@ -2413,8 +2413,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2413
2413
var bindings = controllerDirective . $$bindings . bindToController ;
2414
2414
2415
2415
if ( controller . identifier && bindings ) {
2416
- removeControllerBindingWatches =
2416
+ controller . bindingInfo =
2417
2417
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2418
+ } else {
2419
+ controller . bindingInfo = { } ;
2418
2420
}
2419
2421
2420
2422
var controllerResult = controller ( ) ;
@@ -2423,8 +2425,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2423
2425
// from setupControllers
2424
2426
controller . instance = controllerResult ;
2425
2427
$element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2426
- removeControllerBindingWatches && removeControllerBindingWatches ( ) ;
2427
- removeControllerBindingWatches =
2428
+ controller . bindingInfo . removeWatches && controller . bindingInfo . removeWatches ( ) ;
2429
+ controller . bindingInfo =
2428
2430
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2429
2431
}
2430
2432
}
@@ -2440,6 +2442,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2440
2442
// Handle the init and destroy lifecycle hooks on all controllers that have them
2441
2443
forEach ( elementControllers , function ( controller ) {
2442
2444
var controllerInstance = controller . instance ;
2445
+ if ( isFunction ( controllerInstance . $onChanges ) ) {
2446
+ controllerInstance . $onChanges ( controller . bindingInfo . initialChanges ) ;
2447
+ }
2443
2448
if ( isFunction ( controllerInstance . $onInit ) ) {
2444
2449
controllerInstance . $onInit ( ) ;
2445
2450
}
@@ -3086,6 +3091,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3086
3091
// only occurs for isolate scopes and new scopes with controllerAs.
3087
3092
function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
3088
3093
var removeWatchCollection = [ ] ;
3094
+ var initialChanges = { } ;
3089
3095
var changes ;
3090
3096
forEach ( bindings , function initializeBinding ( definition , scopeName ) {
3091
3097
var attrName = definition . attrName ,
@@ -3118,7 +3124,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3118
3124
// the value to boolean rather than a string, so we special case this situation
3119
3125
destination [ scopeName ] = lastValue ;
3120
3126
}
3121
- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3127
+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
3122
3128
break ;
3123
3129
3124
3130
case '=' :
@@ -3174,7 +3180,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3174
3180
parentGet = $parse ( attrs [ attrName ] ) ;
3175
3181
3176
3182
destination [ scopeName ] = parentGet ( scope ) ;
3177
- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3183
+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
3178
3184
3179
3185
removeWatch = scope . $watch ( parentGet , function parentValueWatchAction ( newParentValue ) {
3180
3186
var oldValue = destination [ scopeName ] ;
@@ -3226,9 +3232,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3226
3232
changes = undefined ;
3227
3233
}
3228
3234
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
+ }
3232
3241
}
3233
3242
} ;
3234
3243
}
0 commit comments