@@ -81,27 +81,43 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF
81
81
* @param {function() } action The callback to execute. function($window, $document)
82
82
* $document is a jQuery wrapped document.
83
83
*/
84
- angular . scenario . Application . prototype . executeAction = function ( action ) {
85
- var self = this ;
86
- var $window = this . getWindow_ ( ) ;
87
- if ( ! $window . document ) {
88
- throw 'Sandbox Error: Application document not accessible.' ;
89
- }
90
- if ( ! $window . angular ) {
91
- return action . call ( this , $window , _jQuery ( $window . document ) ) ;
92
- }
93
- angularInit ( $window . document , function ( element ) {
94
- var $injector = $window . angular . element ( element ) . injector ( ) ;
95
- var $element = _jQuery ( element ) ;
84
+ angular . scenario . Application . prototype . executeAction = function ( action )
85
+ {
86
+ var self = this ;
87
+ var $window = this . getWindow_ ( ) ;
88
+ if ( ! $window . document ) {
89
+ throw 'Sandbox Error: Application document not accessible.' ;
90
+ }
91
+
92
+ if ( ! $window . angular ) {
93
+ return action . call ( this , $window , _jQuery ( $window . document ) ) ;
94
+ }
95
+
96
+ var initialisedWithNgAppDirective = false ;
97
+
98
+ // angularInit calls this function only if ng-app directive is detected
99
+ var initFn = function ( element ) {
100
+ initialisedWithNgAppDirective = true ;
101
+
102
+ var $injector = $window . angular . element ( element ) . injector ( ) ;
103
+ var $element = _jQuery ( element ) ;
104
+
105
+ $element . injector = function ( ) {
106
+ return $injector ;
107
+ } ;
108
+
109
+ $injector . invoke ( function ( $browser ) {
110
+ $browser . notifyWhenNoOutstandingRequests ( function ( ) {
111
+ action . call ( self , $window , $element ) ;
112
+ } ) ;
113
+ } ) ;
114
+ } ;
96
115
97
- $element . injector = function ( ) {
98
- return $injector ;
99
- } ;
116
+ // original implementation searches for ng-app and attaches to angular if found
117
+ angularInit ( $window . document , initFn ) ;
100
118
101
- $injector . invoke ( function ( $browser ) {
102
- $browser . notifyWhenNoOutstandingRequests ( function ( ) {
103
- action . call ( self , $window , $element ) ;
104
- } ) ;
105
- } ) ;
106
- } ) ;
119
+ if ( ! initialisedWithNgAppDirective ) {
120
+ // ng-app not found so manually attaching to the root of document
121
+ initFn ( $window . document ) ;
122
+ }
107
123
} ;
0 commit comments