Skip to content

Commit

Permalink
feat(core/change_detection): properly inject ChangeDetectorRef as loc…
Browse files Browse the repository at this point in the history
…al dependency to component/directive
  • Loading branch information
Hotell committed May 8, 2016
1 parent e3c6ecc commit 3be07ad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/directives/util/util.ts
Expand Up @@ -20,6 +20,7 @@ import { StringWrapper } from '../../../facade/primitives';
import { ChangeDetectionUtil, SimpleChange } from '../../change_detection/change_detection_util';
import { changesQueueService } from '../../change_detection/changes_queue';
import { EventEmitter } from '../../../facade/async';
import { ChangeDetectorRef } from '../../change_detection/change_detector_ref';

const REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/;

Expand Down Expand Up @@ -259,12 +260,15 @@ export function directiveControllerFactory<T extends DirectiveCtrl,U extends Typ
metadata: DirectiveMetadata | ComponentMetadata
): T & U {

const { $scope, $element, $attrs } = locals;
const _services = {
$parse: $injector.get<ng.IParseService>( '$parse' ),
$interpolate: $injector.get<ng.IInterpolateService>( '$interpolate' ),
$rootScope: $injector.get<ng.IRootScopeService>( '$rootScope' )
};
const { $scope, $element, $attrs } = locals;
const _localServices = {
changeDetectorRef: ChangeDetectorRef.create( $scope )
};

// Create an instance of the controller without calling its constructor
const instance = Object.create( controller.prototype );
Expand Down Expand Up @@ -302,7 +306,7 @@ export function directiveControllerFactory<T extends DirectiveCtrl,U extends Typ
const initialInstanceBindingValues = getInitialBindings( instance );

// Finally, invoke the constructor using the injection array and the captured locals
$injector.invoke( controller, instance, StringMapWrapper.assign( locals, $requires ) );
$injector.invoke( controller, instance, StringMapWrapper.assign( locals, _localServices, $requires ) );

reassignBindingsAndCreteEventEmitters( instance, initialInstanceBindingValues );

Expand Down Expand Up @@ -334,7 +338,7 @@ export function directiveControllerFactory<T extends DirectiveCtrl,U extends Typ
// and which have set default values in constructor. We need to store them and reassign after this invoke
const initialInstanceBindingValues = getInitialBindings( instance );

$injector.invoke( controller, instance, StringMapWrapper.assign( locals, $requires ) );
$injector.invoke( controller, instance, StringMapWrapper.assign( locals, _localServices, $requires ) );

reassignBindingsAndCreteEventEmitters( instance, initialInstanceBindingValues );

Expand Down

0 comments on commit 3be07ad

Please sign in to comment.