@@ -145,7 +145,7 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
145145 }
146146
147147 activate ( instruction ) {
148- let previousInstruction = this . currentInstruction ;
148+ this . previousInstruction = this . currentInstruction ;
149149 this . currentInstruction = instruction ;
150150
151151 let componentName = this . controller . $$componentName = instruction . componentType ;
@@ -154,13 +154,14 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
154154 throw new Error ( 'Component is not a string for ' + instruction . urlPath ) ;
155155 }
156156
157- this . controller . $$routeParams = instruction . params ;
158157 this . controller . $$template =
159158 '<' + dashCase ( componentName ) + ' router="$$router"></' + dashCase ( componentName ) + '>' ;
160159 this . controller . $$router = this . router . childRouter ( instruction . componentType ) ;
160+ this . controller . $$outlet = this ;
161161
162162 let newScope = scope . $new ( ) ;
163163 newScope . $$router = this . controller . $$router ;
164+ this . deferredActivation = $q . defer ( ) ;
164165
165166 let clone = $transclude ( newScope , clone => {
166167 $animate . enter ( clone , null , this . currentElement || element ) ;
@@ -169,15 +170,7 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
169170
170171 this . currentElement = clone ;
171172 this . currentScope = newScope ;
172-
173- // TODO: prefer the other directive retrieving the controller
174- // by debug mode
175- this . currentController = this . currentElement . children ( ) . eq ( 0 ) . controller ( componentName ) ;
176-
177- if ( this . currentController && this . currentController . $routerOnActivate ) {
178- return this . currentController . $routerOnActivate ( instruction , previousInstruction ) ;
179- }
180- return $q . when ( ) ;
173+ return this . deferredActivation . promise ;
181174 }
182175 }
183176
@@ -200,21 +193,32 @@ function ngOutletFillContentDirective($compile) {
200193 link : ( scope , element , attrs , ctrl ) => {
201194 let template = ctrl . $$template ;
202195 element . html ( template ) ;
203- let link = $compile ( element . contents ( ) ) ;
204- link ( scope ) ;
196+ $compile ( element . contents ( ) ) ( scope ) ;
197+ }
198+ } ;
199+ }
200+
205201
206- // TODO: move to primary directive
207- let componentInstance = scope [ ctrl . $$componentName ] ;
208- if ( componentInstance ) {
209- ctrl . $$currentComponent = componentInstance ;
210202
211- componentInstance . $router = ctrl . $$router ;
212- componentInstance . $routeParams = ctrl . $$routeParams ;
203+ function routerTriggerDirective ( $q ) {
204+ return {
205+ require : '^ngOutlet' ,
206+ priority : - 1000 ,
207+ link : function ( scope , element , attr , ngOutletCtrl ) {
208+ var promise = $q . when ( ) ;
209+ var outlet = ngOutletCtrl . $$outlet ;
210+ var currentComponent = outlet . currentController =
211+ element . controller ( ngOutletCtrl . $$componentName ) ;
212+ if ( currentComponent . $routerOnActivate ) {
213+ promise = $q . when ( currentComponent . $routerOnActivate ( outlet . currentInstruction ,
214+ outlet . previousInstruction ) ) ;
213215 }
216+ promise . then ( outlet . deferredActivation . resolve , outlet . deferredActivation . reject ) ;
214217 }
215218 } ;
216219}
217220
221+
218222/**
219223 * @name ngLink
220224 * @description
@@ -289,7 +293,8 @@ function dashCase(str: string): string {
289293angular . module ( 'ngComponentRouter' , [ ] )
290294 . directive ( 'ngOutlet' , [ '$animate' , '$q' , '$router' , ngOutletDirective ] )
291295 . directive ( 'ngOutlet' , [ '$compile' , ngOutletFillContentDirective ] )
292- . directive ( 'ngLink' , [ '$router' , '$parse' , ngLinkDirective ] ) ;
296+ . directive ( 'ngLink' , [ '$router' , '$parse' , ngLinkDirective ] )
297+ . directive ( 'router' , [ '$q' , routerTriggerDirective ] ) ;
293298
294299/*
295300 * A module for inspecting controller constructors
0 commit comments