@@ -23,6 +23,12 @@ const getProviders = (injector) => {
2323 return providers ;
2424} ;
2525
26+ // These are provide()d as the string UiView.PARENT_INJECT
27+ export interface ParentUiViewInject {
28+ context : ViewContext ;
29+ fqn : string ;
30+ }
31+
2632/**
2733 * A UI-Router viewport directive, which is filled in by a view (component) on a state.
2834 *
@@ -99,29 +105,25 @@ export class UiView {
99105 deregister : Function ;
100106 uiViewData : any = { } ;
101107
102- static INJECT = {
103- fqn : "UiView.parentFQN" ,
104- context : "UiView.parentContext"
105- } ;
108+ static PARENT_INJECT = "UiView.PARENT_INJECT" ;
106109
107110 constructor (
108111 public router : UIRouter ,
109- @Inject ( UiView . INJECT . context ) public parentContext : ViewContext ,
110- @Inject ( UiView . INJECT . fqn ) public parentFqn : string ,
112+ @Inject ( UiView . PARENT_INJECT ) public parent : ParentUiViewInject ,
111113 public dcl : DynamicComponentLoader ,
112114 public elementRef : ElementRef ,
113115 public injector : Injector
114116 ) { }
115117
116118 ngOnInit ( ) {
117- let parentFqn = this . parentFqn ;
119+ let parentFqn = this . parent . fqn ;
118120 let name = this . name || '$default' ;
119121
120122 this . uiViewData = {
121123 id : id ++ ,
122124 name : name ,
123125 fqn : parentFqn ? parentFqn + "." + name : name ,
124- creationContext : this . parentContext ,
126+ creationContext : this . parent . context ,
125127 configUpdated : this . viewConfigUpdated . bind ( this ) ,
126128 config : undefined
127129 } ;
@@ -131,10 +133,11 @@ export class UiView {
131133
132134 disposeLast ( ) {
133135 if ( this . componentRef ) this . componentRef . dispose ( ) ;
136+ this . componentRef = null ;
134137 }
135138
136139 ngOnDestroy ( ) {
137- this . deregister ( ) ;
140+ if ( this . deregister ) this . deregister ( ) ;
138141 this . disposeLast ( ) ;
139142 }
140143
@@ -159,11 +162,10 @@ export class UiView {
159162 let rc = config . node . resolveContext ;
160163 let resolvables = rc . getResolvables ( ) ;
161164 let rawProviders = Object . keys ( resolvables ) . map ( key => provide ( key , { useValue : resolvables [ key ] . data } ) ) ;
162- rawProviders . push ( provide ( UiView . INJECT . context , { useValue : config . viewDecl . $context } ) ) ;
163- rawProviders . push ( provide ( UiView . INJECT . fqn , { useValue : uiViewData . fqn } ) ) ;
165+ rawProviders . push ( provide ( UiView . PARENT_INJECT , { useValue : { context : config . viewDecl . $context , fqn : uiViewData . fqn } } ) ) ;
164166 let providers = Injector . resolve ( rawProviders ) ;
165167
166- let exclusions = [ UiView . INJECT . context , UiView . INJECT . fqn ] ;
168+ let exclusions = [ UiView . PARENT_INJECT ] ;
167169 providers = getProviders ( injector ) . filter ( x => exclusions . indexOf ( x . key . displayName ) === - 1 ) . concat ( providers ) ;
168170
169171 // The 'controller' should be a Component class
0 commit comments