Skip to content

Commit 6d2d4ed

Browse files
fix(module): Use generic type on ModuleWithProviders typing
fixes #445
1 parent 6ad37d9 commit 6d2d4ed

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/angular-hybrid.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ export function objectFactory() {
122122
*/
123123
@Component({
124124
selector: 'ui-view-ng-upgrade',
125-
template: `
126-
<ui-view [name]="name"></ui-view>
127-
`,
125+
template: ` <ui-view [name]="name"></ui-view> `,
128126
// provide a blank object as PARENT_INJECT.
129127
// The component will add property getters when it is constructed.
130128
viewProviders: [{ provide: UIView.PARENT_INJECT, useFactory: objectFactory }],
@@ -145,23 +143,20 @@ export class UIViewNgUpgrade {
145143

146144
// The ng2 ui-view component is inside this ui-view-ng-upgrade directive, which is inside the ng1 "host" ui-view.
147145
// Both ui-views share the same "view context" information (the view's fqn and created-by-state context information)
148-
const ng1elem = angular
149-
.element(ref.nativeElement)
150-
.parent()
151-
.parent();
146+
const ng1elem = angular.element(ref.nativeElement).parent().parent();
152147

153148
// Expose getters on PARENT_INJECT for context (creation state) and fqn (view address)
154149
// These will be used by further nested UIView
155150
Object.defineProperty(parent, 'context', {
156-
get: function() {
151+
get: function () {
157152
const data = ng1elem['inheritedData']('$uiView');
158153
return data && data.$cfg ? data.$cfg.viewDecl.$context : registry.root();
159154
},
160155
enumerable: true,
161156
});
162157

163158
Object.defineProperty(parent, 'fqn', {
164-
get: function() {
159+
get: function () {
165160
const data = ng1elem['inheritedData']('$uiView');
166161
return data && data.$uiView ? data.$uiView.fqn : null;
167162
},
@@ -177,7 +172,7 @@ export class UIViewNgUpgrade {
177172
// Register the ng1 DI '$uiRouter' object as an ng2 Provider.
178173
export function uiRouterUpgradeFactory(router: UIRouter, injector: Injector) {
179174
const modules: StatesModule[] = injector.get<StatesModule[]>(UIROUTER_MODULE_TOKEN, []);
180-
modules.forEach(module => applyModuleConfig(router, injector, module));
175+
modules.forEach((module) => applyModuleConfig(router, injector, module));
181176
return router;
182177
}
183178

@@ -211,14 +206,14 @@ export function getParentUIViewInject(r: StateRegistry): ParentUIViewInject {
211206
exports: [UIViewNgUpgrade, UIRouterModule],
212207
})
213208
export class UIRouterUpgradeModule {
214-
static forRoot(module: NgHybridStatesModule = {}): ModuleWithProviders {
209+
static forRoot(module: NgHybridStatesModule = {}): ModuleWithProviders<UIRouterUpgradeModule> {
215210
return {
216211
ngModule: UIRouterUpgradeModule,
217212
providers: makeChildProviders(module as StatesModule),
218213
};
219214
}
220215

221-
static forChild(module: NgHybridStatesModule = {}): ModuleWithProviders {
216+
static forChild(module: NgHybridStatesModule = {}): ModuleWithProviders<UIRouterUpgradeModule> {
222217
return {
223218
ngModule: UIRouterModule,
224219
providers: makeChildProviders(module as StatesModule),
@@ -229,10 +224,13 @@ export class UIRouterUpgradeModule {
229224
// Downgrade the UIViewNgUpgrade ng2 Component to an ng1 directive.
230225
// The directive is used in a (generated) view template by the (host) ng1 ui-router,
231226
// whenever it finds a view configured with a `component: <Ng2ComponentClass>`
232-
upgradeModule.directive('uiViewNgUpgrade', <any>downgradeComponent({
233-
component: UIViewNgUpgrade,
234-
inputs: ['name'],
235-
}));
227+
upgradeModule.directive(
228+
'uiViewNgUpgrade',
229+
<any>downgradeComponent({
230+
component: UIViewNgUpgrade,
231+
inputs: ['name'],
232+
})
233+
);
236234

237235
upgradeModule.run([
238236
'$injector',
@@ -246,7 +244,7 @@ upgradeModule.run([
246244
// This mimics how ui-router-ng2 exposes the root ng2 Injector, but
247245
// it retrieves from ng1 injector first, then ng2 injector if the token isn't found.
248246
const mergedInjector = {
249-
get: function(token: any, ng2NotFoundValue?: any) {
247+
get: function (token: any, ng2NotFoundValue?: any) {
250248
if (ng1Injector.has(token)) {
251249
return ng1Injector.get(token);
252250
}
@@ -280,7 +278,7 @@ upgradeModule.config([
280278
upgradeModule.config([
281279
'$stateRegistryProvider',
282280
($stateRegistry: StateRegistry) => {
283-
$stateRegistry.decorator('views', function(state: StateObject, parentFn: Function) {
281+
$stateRegistry.decorator('views', function (state: StateObject, parentFn: Function) {
284282
const views = parentFn(state);
285283

286284
forEach(views, (viewDecl: any, viewName: string) => {

0 commit comments

Comments
 (0)