@@ -2372,7 +2372,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2372
2372
2373
2373
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
2374
2374
var i , ii , linkFn , isolateScope , controllerScope , elementControllers , transcludeFn , $element ,
2375
- attrs , removeScopeBindingWatches , removeControllerBindingWatches ;
2375
+ attrs , scopeBindingInfo ;
2376
2376
2377
2377
if ( compileNode === linkNode ) {
2378
2378
attrs = templateAttrs ;
@@ -2411,11 +2411,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2411
2411
compile . $$addScopeClass ( $element , true ) ;
2412
2412
isolateScope . $$isolateBindings =
2413
2413
newIsolateScopeDirective . $$isolateBindings ;
2414
- removeScopeBindingWatches = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2414
+ scopeBindingInfo = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2415
2415
isolateScope . $$isolateBindings ,
2416
2416
newIsolateScopeDirective ) ;
2417
- if ( removeScopeBindingWatches ) {
2418
- isolateScope . $on ( '$destroy' , removeScopeBindingWatches ) ;
2417
+ if ( scopeBindingInfo . removeWatches ) {
2418
+ isolateScope . $on ( '$destroy' , scopeBindingInfo . removeWatches ) ;
2419
2419
}
2420
2420
}
2421
2421
@@ -2426,8 +2426,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2426
2426
var bindings = controllerDirective . $$bindings . bindToController ;
2427
2427
2428
2428
if ( controller . identifier && bindings ) {
2429
- removeControllerBindingWatches =
2429
+ controller . bindingInfo =
2430
2430
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2431
+ } else {
2432
+ controller . bindingInfo = { } ;
2431
2433
}
2432
2434
2433
2435
var controllerResult = controller ( ) ;
@@ -2436,8 +2438,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2436
2438
// from setupControllers
2437
2439
controller . instance = controllerResult ;
2438
2440
$element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2439
- removeControllerBindingWatches && removeControllerBindingWatches ( ) ;
2440
- removeControllerBindingWatches =
2441
+ controller . bindingInfo . removeWatches && controller . bindingInfo . removeWatches ( ) ;
2442
+ controller . bindingInfo =
2441
2443
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2442
2444
}
2443
2445
}
@@ -2453,6 +2455,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2453
2455
// Handle the init and destroy lifecycle hooks on all controllers that have them
2454
2456
forEach ( elementControllers , function ( controller ) {
2455
2457
var controllerInstance = controller . instance ;
2458
+ if ( isFunction ( controllerInstance . $onChanges ) ) {
2459
+ controllerInstance . $onChanges ( controller . bindingInfo . initialChanges ) ;
2460
+ }
2456
2461
if ( isFunction ( controllerInstance . $onInit ) ) {
2457
2462
controllerInstance . $onInit ( ) ;
2458
2463
}
@@ -3099,6 +3104,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3099
3104
// only occurs for isolate scopes and new scopes with controllerAs.
3100
3105
function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
3101
3106
var removeWatchCollection = [ ] ;
3107
+ var initialChanges = { } ;
3102
3108
var changes ;
3103
3109
forEach ( bindings , function initializeBinding ( definition , scopeName ) {
3104
3110
var attrName = definition . attrName ,
@@ -3131,7 +3137,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3131
3137
// the value to boolean rather than a string, so we special case this situation
3132
3138
destination [ scopeName ] = lastValue ;
3133
3139
}
3134
- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3140
+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
3135
3141
break ;
3136
3142
3137
3143
case '=' :
@@ -3187,7 +3193,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3187
3193
parentGet = $parse ( attrs [ attrName ] ) ;
3188
3194
3189
3195
destination [ scopeName ] = parentGet ( scope ) ;
3190
- recordChanges ( scopeName , destination [ scopeName ] , _UNINITIALIZED_VALUE ) ;
3196
+ initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
3191
3197
3192
3198
removeWatch = scope . $watch ( parentGet , function parentValueWatchAction ( newParentValue ) {
3193
3199
var oldValue = destination [ scopeName ] ;
@@ -3239,9 +3245,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3239
3245
changes = undefined ;
3240
3246
}
3241
3247
3242
- return removeWatchCollection . length && function removeWatches ( ) {
3243
- for ( var i = 0 , ii = removeWatchCollection . length ; i < ii ; ++ i ) {
3244
- removeWatchCollection [ i ] ( ) ;
3248
+ return {
3249
+ initialChanges : initialChanges ,
3250
+ removeWatches : removeWatchCollection . length && function removeWatches ( ) {
3251
+ for ( var i = 0 , ii = removeWatchCollection . length ; i < ii ; ++ i ) {
3252
+ removeWatchCollection [ i ] ( ) ;
3253
+ }
3245
3254
}
3246
3255
} ;
3247
3256
}
0 commit comments