1- /** @module common */ /** for typedoc */
2-
31/**
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
610 */
711
12+ /** for typedoc */
813/// <reference path='../../typings/angularjs/angular.d.ts' />
914import { IQService } from "angular" ;
1015import { 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" ;
1318
1419let app = angular . module ( "ui.router.angular1" , [ ] ) ;
1520
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-
3121/**
3222 * Annotates a controller expression (may be a controller function(), a "controllername",
3323 * or "controllername as name")
@@ -42,7 +32,7 @@ export let runtime: IRuntime = {
4232 */
4333
4434export function annotateController ( controllerExpression ) : string [ ] {
45- let $injector = runtime . $injector ;
35+ let $injector = services . $injector ;
4636 let $controller = $injector . get ( "$controller" ) ;
4737 let oldInstantiate = $injector . instantiate ;
4838 try {
@@ -61,9 +51,10 @@ export function annotateController(controllerExpression): string[] {
6151 }
6252}
6353
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 ;
6758}
6859
6960app . run ( runBlock ) ;
@@ -76,34 +67,34 @@ let router = null;
7667ng1UIRouter . $inject = [ '$locationProvider' ] ;
7768function ng1UIRouter ( $locationProvider ) {
7869 router = new Router ( ) ;
79- bindFunctions ( [ 'hashPrefix' ] , $locationProvider , services . location ) ;
70+ bindFunctions ( [ 'hashPrefix' ] , $locationProvider , services . locationConfig ) ;
8071
8172 this . $get = $get ;
8273 $get . $inject = [ '$location' , '$browser' , '$sniffer' ] ;
8374 function $get ( $location , $browser , $sniffer ) {
8475
85- services . location . html5Mode = function ( ) {
76+ services . locationConfig . html5Mode = function ( ) {
8677 var html5Mode = $locationProvider . html5Mode ( ) ;
8778 html5Mode = isObject ( html5Mode ) ? html5Mode . enabled : html5Mode ;
8879 return html5Mode && $sniffer . history ;
8980 } ;
9081
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 ) ;
9485
9586 return router ;
9687 }
9788}
9889
99- angular . module ( 'ui.router.init' , [ 'ng' ] ) . provider ( "ng1UIRouter" , < any > ng1UIRouter ) ;
90+ angular . module ( 'ui.router.init' , [ ] ) . provider ( "ng1UIRouter" , < any > ng1UIRouter ) ;
10091// Register as a provider so it's available to other providers
10192angular . module ( 'ui.router.util' ) . provider ( '$urlMatcherFactory' , [ 'ng1UIRouterProvider' , ( ) => router . urlMatcherFactory ] ) ;
10293angular . module ( 'ui.router.router' ) . provider ( '$urlRouter' , [ 'ng1UIRouterProvider' , ( ) => router . urlRouterProvider ] ) ;
10394angular . module ( 'ui.router.state' ) . provider ( '$state' , [ 'ng1UIRouterProvider' , ( ) => router . stateProvider ] ) ;
10495
10596/* 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 ) { } ] ) ;
10798angular . module ( 'ui.router.state' ) . run ( [ '$state' , function ( $state ) { } ] ) ;
10899angular . module ( 'ui.router.util' ) . run ( [ '$urlMatcherFactory' , function ( $urlMatcherFactory ) { } ] ) ;
109100
0 commit comments