@@ -23,6 +23,12 @@ const getProviders = (injector) => {
23
23
return providers ;
24
24
} ;
25
25
26
+ // These are provide()d as the string UiView.PARENT_INJECT
27
+ export interface ParentUiViewInject {
28
+ context : ViewContext ;
29
+ fqn : string ;
30
+ }
31
+
26
32
/**
27
33
* A UI-Router viewport directive, which is filled in by a view (component) on a state.
28
34
*
@@ -99,29 +105,25 @@ export class UiView {
99
105
deregister : Function ;
100
106
uiViewData : any = { } ;
101
107
102
- static INJECT = {
103
- fqn : "UiView.parentFQN" ,
104
- context : "UiView.parentContext"
105
- } ;
108
+ static PARENT_INJECT = "UiView.PARENT_INJECT" ;
106
109
107
110
constructor (
108
111
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 ,
111
113
public dcl : DynamicComponentLoader ,
112
114
public elementRef : ElementRef ,
113
115
public injector : Injector
114
116
) { }
115
117
116
118
ngOnInit ( ) {
117
- let parentFqn = this . parentFqn ;
119
+ let parentFqn = this . parent . fqn ;
118
120
let name = this . name || '$default' ;
119
121
120
122
this . uiViewData = {
121
123
id : id ++ ,
122
124
name : name ,
123
125
fqn : parentFqn ? parentFqn + "." + name : name ,
124
- creationContext : this . parentContext ,
126
+ creationContext : this . parent . context ,
125
127
configUpdated : this . viewConfigUpdated . bind ( this ) ,
126
128
config : undefined
127
129
} ;
@@ -131,10 +133,11 @@ export class UiView {
131
133
132
134
disposeLast ( ) {
133
135
if ( this . componentRef ) this . componentRef . dispose ( ) ;
136
+ this . componentRef = null ;
134
137
}
135
138
136
139
ngOnDestroy ( ) {
137
- this . deregister ( ) ;
140
+ if ( this . deregister ) this . deregister ( ) ;
138
141
this . disposeLast ( ) ;
139
142
}
140
143
@@ -159,11 +162,10 @@ export class UiView {
159
162
let rc = config . node . resolveContext ;
160
163
let resolvables = rc . getResolvables ( ) ;
161
164
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 } } ) ) ;
164
166
let providers = Injector . resolve ( rawProviders ) ;
165
167
166
- let exclusions = [ UiView . INJECT . context , UiView . INJECT . fqn ] ;
168
+ let exclusions = [ UiView . PARENT_INJECT ] ;
167
169
providers = getProviders ( injector ) . filter ( x => exclusions . indexOf ( x . key . displayName ) === - 1 ) . concat ( providers ) ;
168
170
169
171
// The 'controller' should be a Component class
0 commit comments