1
1
"use strict" ;
2
2
/// <reference path='../../typings/angularjs/angular.d.ts' />
3
- import { IPromise } from "angular" ;
4
- import { isInjectable , isString , defaults , extend , curry , addPairToObj , prop , pick , removeFrom , isEq , val , TypedMap } from "../common/common" ;
3
+ import { isInjectable , isString , extend , curry , addPairToObj , prop , pick , removeFrom , isEq , val , TypedMap } from "../common/common" ;
5
4
import trace from "../common/trace" ;
6
5
import { IStateViewConfig , IViewDeclaration } from "../state/interface" ;
7
6
import { IUiViewData , IContextRef } from "./interface" ;
7
+ import ResolveInjector from "../resolve/resolveInjector" ;
8
8
9
9
/**
10
10
* Given a raw view name from a views: config, returns a normalized target viewName and contextAnchor
@@ -43,10 +43,6 @@ function normalizeUiViewTarget(rawViewName = "") {
43
43
*/
44
44
export class ViewConfig {
45
45
viewDeclarationObj : IViewDeclaration ;
46
- promises : {
47
- template : IPromise < string > ,
48
- controller : IPromise < Function >
49
- } ;
50
46
51
47
template : string ;
52
48
controller : Function ;
@@ -86,9 +82,8 @@ export class ViewConfig {
86
82
return ! ! ( viewDef . template || viewDef . templateUrl || viewDef . templateProvider ) ;
87
83
}
88
84
89
- getTemplate ( $factory ) {
90
- let locals = this . locals , viewDef = this . viewDeclarationObj ;
91
- return $factory . fromConfig ( viewDef , this . params , locals . invoke . bind ( locals ) ) ;
85
+ getTemplate ( $factory , injector : ResolveInjector ) {
86
+ return $factory . fromConfig ( this . viewDeclarationObj , this . params , injector . invokeLater . bind ( injector ) ) ;
92
87
}
93
88
94
89
/**
@@ -97,10 +92,10 @@ export class ViewConfig {
97
92
*
98
93
* @returns {Function|Promise.<Function> } Returns a controller, or a promise that resolves to a controller.
99
94
*/
100
- getController ( ) {
95
+ getController ( injector : ResolveInjector ) {
101
96
//* @param {Object } locals A context object from transition.context() to invoke a function in the correct context
102
97
let provider = this . viewDeclarationObj . controllerProvider ;
103
- return isInjectable ( provider ) ? this . locals . invoke ( provider ) : this . viewDeclarationObj . controller ;
98
+ return isInjectable ( provider ) ? injector . invokeLater ( provider , { } ) : this . viewDeclarationObj . controller ;
104
99
}
105
100
}
106
101
@@ -143,50 +138,16 @@ function $View( $rootScope, $templateFactory, $q, $timeout) {
143
138
* `$templateFactory.fromConfig()`, including `params` and `locals`.
144
139
* @return {Promise.<string> } Returns a promise that resolves to the value of the template loaded.
145
140
*/
146
- this . load = function load ( viewConfig : ViewConfig , options ) {
147
- options = defaults ( options , {
148
- context : null ,
149
- parent : null ,
150
- notify : true ,
151
- async : true ,
152
- params : { }
153
- } ) ;
154
-
141
+ this . load = function load ( viewConfig : ViewConfig , injector : ResolveInjector ) {
155
142
if ( ! viewConfig . hasTemplate ( ) )
156
143
throw new Error ( `No template configuration specified for '${ viewConfig . uiViewName } @${ viewConfig . uiViewContextAnchor } '` ) ;
157
144
158
- if ( options . notify ) {
159
- /**
160
- * @ngdoc event
161
- * @name ui.router.state.$state#$viewContentLoading
162
- * @eventOf ui.router.state.$view
163
- * @eventType broadcast on root scope
164
- * @description
165
- *
166
- * Fired once the view **begins loading**, *before* the DOM is rendered.
167
- *
168
- * @param {Object } event Event object.
169
- * @param {Object } viewConfig The view config properties (template, controller, etc).
170
- *
171
- * @example
172
- *
173
- * <pre>
174
- * $scope.$on('$viewContentLoading', function(event, viewConfig) {
175
- * // Access to all the view config properties.
176
- * // and one special property 'targetView'
177
- * // viewConfig.targetView
178
- * });
179
- * </pre>
180
- */
181
- $rootScope . $broadcast ( '$viewContentLoading' , extend ( { targetView : name } , options ) ) ;
182
- }
183
-
184
- viewConfig . promises = {
185
- template : $q . when ( viewConfig . getTemplate ( $templateFactory ) ) ,
186
- controller : $q . when ( viewConfig . getController ( ) )
145
+ let promises = {
146
+ template : $q . when ( viewConfig . getTemplate ( $templateFactory , injector ) ) ,
147
+ controller : $q . when ( viewConfig . getController ( injector ) )
187
148
} ;
188
149
189
- return $q . all ( viewConfig . promises ) . then ( ( results ) => {
150
+ return $q . all ( promises ) . then ( ( results ) => {
190
151
trace . traceViewServiceEvent ( "Loaded" , viewConfig ) ;
191
152
return extend ( viewConfig , results ) ;
192
153
} ) ;
0 commit comments