Skip to content

Commit d11b7dc

Browse files
BREAKING CHANGE: Remove UIInjector.native infavor of UIInjector.getNative()
BREAKING CHANGE: Remove `stateProvider` from core. Use `stateRegistry` and `stateService` in 88c6494
1 parent d6c2580 commit d11b7dc

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

src/common/interface.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import {noop} from "./common";
55

66
/**
77
* An interface for getting values from dependency injection.
8+
*
9+
* This injector primarily returns resolve values (using a [[ResolveContext]]) that match the given token.
10+
* If no resolve is found for a token, then it will delegate to the native injector.
11+
* The native injector may be Angular 1 `$injector`, Angular 2 `Injector`, or a naive polyfill.
12+
*
13+
* In Angular 2, the native injector might be the root Injector,
14+
* or it might be a lazy loaded `NgModule` injector scoped to a lazy load state tree.
815
*/
916
export interface UIInjector {
1017
/**
@@ -25,18 +32,17 @@ export interface UIInjector {
2532
* injector.get(StateService).go('home');
2633
* ```
2734
*
28-
* Note:
29-
* The code that implements this interface may be Angular 1 `$injector`, Angular 2 `Injector`,
30-
* a [[ResolveContext]], or a `ResolveContext` that delegates to the ng1/ng2 injector if keys are missing.
31-
*
32-
* @param key the key for the value to get. May be a string or arbitrary object.
33-
* @return the Dependency Injection value that matches the key
35+
* @param token the key for the value to get. May be a string or arbitrary object.
36+
* @return the Dependency Injection value that matches the token
3437
*/
35-
get(key: any): any;
38+
get(token: any): any;
3639

3740
/**
3841
* Asynchronously gets a value from the injector
3942
*
43+
* If the [[ResolveContext]] has a [[Resolvable]] matching the token, it will be
44+
* asynchronously resolved.
45+
*
4046
* Returns a promise for a value from the injector.
4147
* Returns resolve values and/or values from the native injector (ng1/ng2).
4248
*
@@ -48,8 +54,23 @@ export interface UIInjector {
4854
* });
4955
* ```
5056
*
51-
* @param key the key for the value to get. May be a string or arbitrary object.
52-
* @return a Promise for the Dependency Injection value that matches the key
57+
* @param token the key for the value to get. May be a string or arbitrary object.
58+
* @return a Promise for the Dependency Injection value that matches the token
59+
*/
60+
getAsync(token: any): Promise<any>;
61+
62+
/**
63+
* Gets a value from the native injector
64+
*
65+
* Returns a value from the native injector, bypassing anything in the [[ResolveContext]].
66+
*
67+
* Example:
68+
* ```js
69+
* let someThing = injector.getNative(SomeToken);
70+
* ```
71+
*
72+
* @param token the key for the value to get. May be a string or arbitrary object.
73+
* @return the Dependency Injection value that matches the token
5374
*/
54-
getAsync(key: any): any;
75+
getNative(token: any): any;
5576
}

src/ng1/services.ts

-24
Original file line numberDiff line numberDiff line change
@@ -301,30 +301,6 @@ export const getLocals = (ctx: ResolveContext) => {
301301
return tuples.reduce(applyPairs, {});
302302
};
303303

304-
/** Adds the angular 1 `$injector` to the `UIInjector` interface */
305-
declare module "../common/interface" {
306-
/**
307-
* This enhances the [[common.UIInjector]] interface by adding the `$injector` service as the [[native]] injector.
308-
*/
309-
interface UIInjector {
310-
/**
311-
* The native Angular 1 `$injector` service
312-
*
313-
* When you have access to a `UIInjector`, this property will contain the native `$injector` Angular 1 service.
314-
*
315-
* @example:
316-
* ```js
317-
*
318-
* $transition.onStart({}, function(transition) {
319-
* var uiInjector = transition.injector();
320-
* var $injector = uiInjector.native;
321-
* var val = $injector.invoke(someFunction);
322-
* });
323-
*/
324-
native: $InjectorLike;
325-
}
326-
}
327-
328304
/** Injectable services */
329305

330306
/**

src/resolve/resolveContext.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class ResolveContext {
159159
let matching = availableResolvables.filter(r => r.token === token);
160160
if (matching.length) return tail(matching);
161161

162-
let fromInjector = this.injector().get(token);
162+
let fromInjector = this.injector().getNative(token);
163163
if (!fromInjector) {
164164
throw new Error("Could not find Dependency Injection token: " + stringify(token));
165165
}
@@ -194,4 +194,8 @@ class UIInjectorImpl implements UIInjector {
194194
if (resolvable) return resolvable.get(this.context);
195195
return services.$q.when(this.native.get(token));
196196
}
197+
198+
getNative(token: any) {
199+
return this.native.get(token);
200+
}
197201
}

0 commit comments

Comments
 (0)