1
- /** @module common */ /** for typedoc */
2
-
3
1
/**
4
- * Provides the implementation for services defined in [[coreservices]], and registers some
5
- * with the angular 1 injector.
2
+ * Angular 1 plugin:
3
+ *
4
+ * - Provides an implementation for the [[CoreServices]] API, based on angular 1 services.
5
+ * - Also registers some services with the angular 1 injector.
6
+ * - Creates and bootstraps a new [[Router]] object, usiong the angular 1 lifecycle
7
+ *
8
+ * @module ng1
9
+ * @preferred
6
10
*/
7
11
12
+ /** for typedoc */
8
13
/// <reference path='../../typings/angularjs/angular.d.ts' />
9
14
import { IQService } from "angular" ;
10
15
import { Router } from "../router" ;
11
- import { services } from "./coreservices" ;
12
- import { isObject } from "./common" ;
16
+ import { services } from "../common /coreservices" ;
17
+ import { isObject } from "../common /common" ;
13
18
14
19
let app = angular . module ( "ui.router.angular1" , [ ] ) ;
15
20
16
- interface IRuntime {
17
- setRuntimeInjector ( $injector : ng . auto . IInjectorService ) ;
18
- $injector : ng . auto . IInjectorService ;
19
- $q : IQService ;
20
- }
21
-
22
- export let runtime : IRuntime = {
23
- setRuntimeInjector : function ( $injector : ng . auto . IInjectorService ) {
24
- runtime . $injector = $injector ;
25
- runtime . $q = $injector . get ( "$q" ) ;
26
- } ,
27
- $injector : undefined ,
28
- $q : undefined
29
- } ;
30
-
31
21
/**
32
22
* Annotates a controller expression (may be a controller function(), a "controllername",
33
23
* or "controllername as name")
@@ -42,7 +32,7 @@ export let runtime: IRuntime = {
42
32
*/
43
33
44
34
export function annotateController ( controllerExpression ) : string [ ] {
45
- let $injector = runtime . $injector ;
35
+ let $injector = services . $injector ;
46
36
let $controller = $injector . get ( "$controller" ) ;
47
37
let oldInstantiate = $injector . instantiate ;
48
38
try {
@@ -61,9 +51,10 @@ export function annotateController(controllerExpression): string[] {
61
51
}
62
52
}
63
53
64
- runBlock . $inject = [ "$injector" ] ;
65
- function runBlock ( $injector ) {
66
- runtime . setRuntimeInjector ( $injector ) ;
54
+ runBlock . $inject = [ '$injector' , '$q' ] ;
55
+ function runBlock ( $injector , $q ) {
56
+ services . $injector = $injector ;
57
+ services . $q = $q ;
67
58
}
68
59
69
60
app . run ( runBlock ) ;
@@ -76,34 +67,34 @@ let router = null;
76
67
ng1UIRouter . $inject = [ '$locationProvider' ] ;
77
68
function ng1UIRouter ( $locationProvider ) {
78
69
router = new Router ( ) ;
79
- bindFunctions ( [ 'hashPrefix' ] , $locationProvider , services . location ) ;
70
+ bindFunctions ( [ 'hashPrefix' ] , $locationProvider , services . locationConfig ) ;
80
71
81
72
this . $get = $get ;
82
73
$get . $inject = [ '$location' , '$browser' , '$sniffer' ] ;
83
74
function $get ( $location , $browser , $sniffer ) {
84
75
85
- services . location . html5Mode = function ( ) {
76
+ services . locationConfig . html5Mode = function ( ) {
86
77
var html5Mode = $locationProvider . html5Mode ( ) ;
87
78
html5Mode = isObject ( html5Mode ) ? html5Mode . enabled : html5Mode ;
88
79
return html5Mode && $sniffer . history ;
89
80
} ;
90
81
91
- var $locationFnNames = [ 'hash' , 'path' , 'replace' , ' search' , 'url' , 'port' , 'protocol' , 'host' ] ;
92
- bindFunctions ( $locationFnNames , $location , services . location ) ;
93
- bindFunctions ( [ 'baseHref' ] , $browser , services . location ) ;
82
+ bindFunctions ( [ "replace" , "url" , "path" , " search" , "hash" ] , $location , services . location ) ;
83
+ bindFunctions ( [ 'port' , 'protocol' , 'host' ] , $location , services . locationConfig ) ;
84
+ bindFunctions ( [ 'baseHref' ] , $browser , services . locationConfig ) ;
94
85
95
86
return router ;
96
87
}
97
88
}
98
89
99
- angular . module ( 'ui.router.init' , [ 'ng' ] ) . provider ( "ng1UIRouter" , < any > ng1UIRouter ) ;
90
+ angular . module ( 'ui.router.init' , [ ] ) . provider ( "ng1UIRouter" , < any > ng1UIRouter ) ;
100
91
// Register as a provider so it's available to other providers
101
92
angular . module ( 'ui.router.util' ) . provider ( '$urlMatcherFactory' , [ 'ng1UIRouterProvider' , ( ) => router . urlMatcherFactory ] ) ;
102
93
angular . module ( 'ui.router.router' ) . provider ( '$urlRouter' , [ 'ng1UIRouterProvider' , ( ) => router . urlRouterProvider ] ) ;
103
94
angular . module ( 'ui.router.state' ) . provider ( '$state' , [ 'ng1UIRouterProvider' , ( ) => router . stateProvider ] ) ;
104
95
105
96
/* This effectively calls $get() to init when we enter runtime */
106
- angular . module ( 'ui.router.state ' ) . run ( [ 'ng1UIRouter' , function ( ng1UIRouter ) { } ] ) ;
97
+ angular . module ( 'ui.router.init ' ) . run ( [ 'ng1UIRouter' , function ( ng1UIRouter ) { } ] ) ;
107
98
angular . module ( 'ui.router.state' ) . run ( [ '$state' , function ( $state ) { } ] ) ;
108
99
angular . module ( 'ui.router.util' ) . run ( [ '$urlMatcherFactory' , function ( $urlMatcherFactory ) { } ] ) ;
109
100
0 commit comments