Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit f7e17f3

Browse files
authoredOct 2, 2017
fix(clientSideScripts): change protractor to support waiting for hybrid app (#4512)
Change protractor to wait for both angular1 hook and angular2 hook so that it can wait for hybrid app correctly. Add an aot hybrid app and testcase to test new change
1 parent 15776b8 commit f7e17f3

19 files changed

+469
-58
lines changed
 

‎lib/clientsidescripts.js

+83-41
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function getNg1Hooks(selector, injectorPlease) {
8686
return {$injector: $injector};
8787
}
8888
}
89-
} catch(err) {}
89+
} catch(err) {}
9090
}
9191
function trySelector(selector) {
9292
var els = document.querySelectorAll(selector);
@@ -133,54 +133,96 @@ function getNg1Hooks(selector, injectorPlease) {
133133
* be passed as a parameter.
134134
*/
135135
functions.waitForAngular = function(rootSelector, callback) {
136+
136137
try {
137-
if (window.angular && !(window.angular.version &&
138-
window.angular.version.major > 1)) {
139-
/* ng1 */
140-
var hooks = getNg1Hooks(rootSelector);
141-
if (hooks.$$testability) {
142-
hooks.$$testability.whenStable(callback);
143-
} else if (hooks.$injector) {
144-
hooks.$injector.get('$browser').
145-
notifyWhenNoOutstandingRequests(callback);
146-
} else if (!!rootSelector) {
147-
throw new Error('Could not automatically find injector on page: "' +
148-
window.location.toString() + '". Consider using config.rootEl');
149-
} else {
150-
throw new Error('root element (' + rootSelector + ') has no injector.' +
151-
' this may mean it is not inside ng-app.');
138+
// Wait for both angular1 testability and angular2 testability.
139+
140+
var testCallback = callback;
141+
142+
// Wait for angular1 testability first and run waitForAngular2 as a callback
143+
var waitForAngular1 = function(callback) {
144+
145+
if (window.angular) {
146+
var hooks = getNg1Hooks(rootSelector);
147+
if (!hooks){
148+
callback(); // not an angular1 app
149+
}
150+
else{
151+
if (hooks.$$testability) {
152+
hooks.$$testability.whenStable(callback);
153+
} else if (hooks.$injector) {
154+
hooks.$injector.get('$browser')
155+
.notifyWhenNoOutstandingRequests(callback);
156+
} else if (!!rootSelector) {
Has conversations. Original line has conversations.
157+
throw new Error(
158+
'Could not automatically find injector on page: "' +
159+
window.location.toString() + '". Consider using config.rootEl');
160+
} else {
161+
throw new Error(
162+
'root element (' + rootSelector + ') has no injector.' +
163+
' this may mean it is not inside ng-app.');
164+
}
165+
}
152166
}
153-
} else if (rootSelector && window.getAngularTestability) {
154-
var el = document.querySelector(rootSelector);
155-
window.getAngularTestability(el).whenStable(callback);
156-
} else if (window.getAllAngularTestabilities) {
157-
var testabilities = window.getAllAngularTestabilities();
158-
var count = testabilities.length;
159-
var decrement = function() {
160-
count--;
167+
else {callback();} // not an angular1 app
168+
};
169+
170+
// Wait for Angular2 testability and then run test callback
171+
var waitForAngular2 = function() {
172+
if (window.getAngularTestability) {
173+
if (rootSelector) {
174+
var testability = null;
175+
var el = document.querySelector(rootSelector);
176+
try{
177+
testability = window.getAngularTestability(el);
178+
}
179+
catch(e){}
180+
if (testability) {
181+
return testability.whenStable(testCallback);
182+
}
183+
}
184+
185+
// Didn't specify root element or testability could not be found
186+
// by rootSelector. This may happen in a hybrid app, which could have
187+
// more than one root.
188+
var testabilities = window.getAllAngularTestabilities();
189+
var count = testabilities.length;
190+
191+
// No angular2 testability, this happens when
192+
// going to a hybrid page and going back to a pure angular1 page
161193
if (count === 0) {
162-
callback();
194+
return testCallback();
163195
}
164-
};
165-
testabilities.forEach(function(testability) {
166-
testability.whenStable(decrement);
167-
});
168-
} else if (!window.angular) {
169-
throw new Error('window.angular is undefined. This could be either ' +
196+
197+
var decrement = function() {
198+
count--;
199+
if (count === 0) {
200+
testCallback();
201+
}
202+
};
203+
testabilities.forEach(function(testability) {
204+
testability.whenStable(decrement);
205+
});
206+
207+
}
208+
else {testCallback();} // not an angular2 app
209+
};
210+
211+
if (!(window.angular) && !(window.getAngularTestability)) {
212+
// no testability hook
213+
throw new Error(
214+
'both angularJS testability and angular testability are undefined.' +
215+
' This could be either ' +
170216
'because this is a non-angular page or because your test involves ' +
171217
'client-side navigation, which can interfere with Protractor\'s ' +
172218
'bootstrapping. See http://git.io/v4gXM for details');
173-
} else if (window.angular.version >= 2) {
174-
throw new Error('You appear to be using angular, but window.' +
175-
'getAngularTestability was never set. This may be due to bad ' +
176-
'obfuscation.');
177-
} else {
178-
throw new Error('Cannot get testability API for unknown angular ' +
179-
'version "' + window.angular.version + '"');
180-
}
219+
} else {waitForAngular1(waitForAngular2);} // Wait for angular1 and angular2
220+
// Testability hooks sequentially
221+
181222
} catch (err) {
182223
callback(err.message);
183224
}
225+
184226
};
185227

186228
/**
@@ -277,7 +319,7 @@ function findRepeaterRows(repeater, exact, index, using) {
277319
var row = rows[index] || [], multiRow = multiRows[index] || [];
278320
return [].concat(row, multiRow);
279321
}
280-
functions.findRepeaterRows = wrapWithHelpers(findRepeaterRows, repeaterMatch);
322+
functions.findRepeaterRows = wrapWithHelpers(findRepeaterRows, repeaterMatch);
281323

282324
/**
283325
* Find all rows of an ng-repeat.
@@ -697,7 +739,7 @@ functions.testForAngular = function(attempts, ng12Hybrid, asyncCallback) {
697739
if (n < 1) {
698740
if (definitelyNg1 && window.angular) {
699741
callback({message: 'angular never provided resumeBootstrap'});
700-
} else if (ng12Hybrid && !window.angular) {
742+
} else if (ng12Hybrid && !window.angular) {
701743
callback({message: 'angular 1 never loaded' +
702744
window.getAllAngularTestabilities ? ' (are you sure this app ' +
703745
'uses ngUpgrade? Try un-setting ng12Hybrid)' : ''});

‎spec/hybrid/async_spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@ describe('async angular1/2 hybrid using ngUpgrade application', function() {
5454
});
5555
});
5656
});
57+
describe('async angular1/2 hybrid using downgrade application', function() {
58+
it('should be able to click buttons and wait for $timeout', function() {
59+
browser.get('/upgrade?downgrade');
60+
61+
var rootBtn = $$('my-app button').first();
62+
expect(rootBtn.getText()).toEqual('Click Count: 0');
63+
rootBtn.click();
64+
expect(rootBtn.getText()).toEqual('Click Count: 1');
65+
66+
var ng2Btn = $$('ng2 button').first();
67+
expect(ng2Btn.getText()).toEqual('Click Count: 0');
68+
ng2Btn.click();
69+
expect(ng2Btn.getText()).toEqual('Click Count: 1');
70+
});
71+
});

‎testapp/app.css

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ li {
2424

2525
li.left {
2626
left: 0;
27-
}
27+
}
2828

2929
li.left.mid {
30-
left: 25%;
30+
left: 20%;
3131
}
3232

33-
li.right {
34-
right: 0;
33+
li.mid{
34+
left : 40%;
3535
}
3636

3737
li.right.mid {
38-
right: 25%;
38+
left: 60%;
39+
}
40+
41+
li.right {
42+
left: 80%;
3943
}
44+

‎testapp/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ <h1>Choose Version</h1>
1414
<li class='mid left'>
1515
<a href='upgrade?no_static'>Hybrid (JIT)</a>
1616
</li>
17-
<li class='mid right'>
17+
<li class='mid'>
1818
<a href='upgrade'>Hybrid (AOT)</a>
1919
</li>
20+
<li class='mid right'>
21+
<a href='upgrade?downgrade'>Hybrid (Downgrade)</a>
22+
</li>
2023
<li class="right">
2124
<a href="ng2">Angular 2</a>
2225
</li>

‎testapp/package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
"tsc": "tsc"
77
},
88
"dependencies": {
9-
"@angular/common": "2.2.1",
10-
"@angular/compiler": "2.2.1",
11-
"@angular/core": "2.2.1",
12-
"@angular/http": "2.2.1",
13-
"@angular/platform-browser": "2.2.1",
14-
"@angular/platform-browser-dynamic": "2.2.1",
15-
"@angular/router": "3.0.0",
16-
"@angular/upgrade": "2.2.1",
9+
"@angular/common": "5.0.0-beta.7",
10+
"@angular/compiler": "5.0.0-beta.7",
11+
"@angular/core": "5.0.0-beta.7",
12+
"@angular/http": "5.0.0-beta.7",
13+
"@angular/platform-browser": "5.0.0-beta.7",
14+
"@angular/animations": "5.0.0-beta.7",
15+
"@angular/platform-browser-dynamic": "5.0.0-beta.7",
16+
"@angular/router": "5.0.0-beta.7",
17+
"@angular/upgrade": "5.0.0-beta.7",
1718
"@types/angular": "^1.5.20",
1819
"@types/core-js": "^0.9.34",
1920
"@types/node": "^6.0.48",
2021
"core-js": "2.4.1",
2122
"reflect-metadata": "0.1.3",
22-
"rxjs": "5.0.0-beta.12",
23+
"rxjs": "5.4.3",
2324
"systemjs": "0.19.27",
24-
"zone.js": "0.6.25"
25+
"zone.js": "0.8.18"
2526
},
2627
"devDependencies": {
2728
"concurrently": "2.2.0",

‎testapp/tsconfig-aot.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"lib": ["es2015", "dom"],
10+
"noImplicitAny": true,
11+
"suppressImplicitAnyIndexErrors": true,
12+
"typeRoots": [
13+
"./node_modules/@types/"
14+
]
15+
},
16+
17+
"files": [
18+
"upgrade/app/downgrade/main.ts",
19+
"upgrade/app/downgrade/ng1.ts",
20+
"upgrade/app/downgrade/ng2.ts"
21+
]
22+
23+
}

‎testapp/upgrade/app/downgrade/main.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎testapp/upgrade/app/downgrade/main.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {downgradeModule} from '@angular/upgrade/static';
2+
declare var angular: angular.IAngularStatic;
3+
4+
import {ng1module} from './ng1';
5+
import {AppModuleNgFactory} from './ng2.ngfactory';
6+
7+
// Bootstrap Ng1 app as usual, but add a downgradedModule for the Angular (2+)
8+
// part of the application.
9+
angular.bootstrap(
10+
document.body, [ng1module.name, downgradeModule(AppModuleNgFactory)]);

‎testapp/upgrade/app/downgrade/ng1.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"__symbolic":"module","version":3,"metadata":{"ng1module":{"__symbolic":"error","message":"Reference to a local symbol","line":0,"character":12,"context":{"name":"angular"}}}},{"__symbolic":"module","version":1,"metadata":{"ng1module":{"__symbolic":"error","message":"Reference to a local symbol","line":0,"character":12,"context":{"name":"angular"}}}}]

‎testapp/upgrade/app/downgrade/ng1.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
declare var angular: angular.IAngularStatic;
2+
3+
function ctrl($scope: any, $timeout: any) {
4+
$scope.callCount = 0;
5+
6+
$scope.clickButton = function() {
7+
$timeout(() => {
8+
$scope.callCount++;
9+
}, 1000);
10+
};
11+
}
12+
ctrl.$inject = ['$scope', '$timeout'];
13+
14+
export const ng1module = angular.module('hybrid', []);
15+
16+
ng1module.component('myApp', {
17+
template: `<h3>ng1</h3><button ng-click="clickButton()">Click Count: {{callCount}}</button>
18+
<ng2></ng2>
19+
`,
20+
controller: ctrl
21+
});

‎testapp/upgrade/app/downgrade/ng2.js

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"__symbolic":"module","version":3,"metadata":{"Ng2Component":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2","template":"\n <h2>ng2</h2>\n <button (click)='clickButton()'>Click Count: {{callCount}}</button>\n "}]}]},"AppModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/platform-browser/animations","name":"BrowserAnimationsModule"}],"declarations":[{"__symbolic":"reference","name":"Ng2Component"}],"entryComponents":[{"__symbolic":"reference","name":"Ng2Component"}]}]}],"members":{"ngDoBootstrap":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"Ng2Component":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2","template":"\n <h2>ng2</h2>\n <button (click)='clickButton()'>Click Count: {{callCount}}</button>\n "}]}]},"AppModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/platform-browser/animations","name":"BrowserAnimationsModule"}],"declarations":[{"__symbolic":"reference","name":"Ng2Component"}],"entryComponents":[{"__symbolic":"reference","name":"Ng2Component"}]}]}],"members":{"ngDoBootstrap":[{"__symbolic":"method"}]}}}}]

‎testapp/upgrade/app/downgrade/ng2.ngfactory.js

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @fileoverview This file is generated by the Angular template compiler.
3+
* Do not edit.
4+
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride}
5+
*/
6+
/* tslint:disable */
7+
8+
9+
import * as i0 from '@angular/core';
10+
import * as i1 from './ng2';
11+
import * as i2 from '@angular/common';
12+
import * as i3 from '@angular/platform-browser';
13+
import * as i4 from '@angular/animations/browser';
14+
import * as i5 from '@angular/platform-browser/animations';
15+
import * as i6 from '@angular/animations';
16+
export const AppModuleNgFactory:i0.NgModuleFactory<i1.AppModule> = i0.ɵcmf(i1.AppModule,
17+
([] as any[]),(_l:any) => {
18+
return i0.ɵmod([i0.ɵmpd(512,i0.ComponentFactoryResolver,i0.ɵCodegenComponentFactoryResolver,
19+
[[8,[Ng2ComponentNgFactory]],[3,i0.ComponentFactoryResolver],i0.NgModuleRef]),
20+
i0.ɵmpd(5120,i0.LOCALE_ID,i0.ɵo,[[3,i0.LOCALE_ID]]),i0.ɵmpd(4608,i2.NgLocalization,
21+
i2.NgLocaleLocalization,[i0.LOCALE_ID,[2,i2.ɵa]]),i0.ɵmpd(4608,i0.Compiler,
22+
i0.Compiler,([] as any[])),i0.ɵmpd(5120,i0.APP_ID,i0.ɵh,([] as any[])),
23+
i0.ɵmpd(5120,i0.IterableDiffers,i0.ɵm,([] as any[])),i0.ɵmpd(5120,i0.KeyValueDiffers,
24+
i0.ɵn,([] as any[])),i0.ɵmpd(4608,i3.DomSanitizer,i3.ɵd,[i2.DOCUMENT]),
25+
i0.ɵmpd(6144,i0.Sanitizer,(null as any),[i3.DomSanitizer]),i0.ɵmpd(4608,
26+
i3.HAMMER_GESTURE_CONFIG,i3.HammerGestureConfig,([] as any[])),i0.ɵmpd(5120,
27+
i3.EVENT_MANAGER_PLUGINS,(p0_0:any,p0_1:any,p1_0:any,p2_0:any,p2_1:any) => {
28+
return [new i3.ɵDomEventsPlugin(p0_0,p0_1),new i3.ɵKeyEventsPlugin(p1_0),
29+
new i3.ɵHammerGesturesPlugin(p2_0,p2_1)];
30+
},[i2.DOCUMENT,i0.NgZone,i2.DOCUMENT,i2.DOCUMENT,i3.HAMMER_GESTURE_CONFIG]),
31+
i0.ɵmpd(4608,i3.EventManager,i3.EventManager,[i3.EVENT_MANAGER_PLUGINS,i0.NgZone]),
32+
i0.ɵmpd(135680,i3.ɵDomSharedStylesHost,i3.ɵDomSharedStylesHost,[i2.DOCUMENT]),
33+
i0.ɵmpd(4608,i3.ɵDomRendererFactory2,i3.ɵDomRendererFactory2,[i3.EventManager,
34+
i3.ɵDomSharedStylesHost]),i0.ɵmpd(5120,i4.AnimationDriver,i5.ɵc,([] as any[])),
35+
i0.ɵmpd(5120,i4.ɵAnimationStyleNormalizer,i5.ɵd,([] as any[])),i0.ɵmpd(4608,
36+
i4.ɵAnimationEngine,i5.ɵb,[i4.AnimationDriver,i4.ɵAnimationStyleNormalizer]),
37+
i0.ɵmpd(5120,i0.RendererFactory2,i5.ɵe,[i3.ɵDomRendererFactory2,i4.ɵAnimationEngine,
38+
i0.NgZone]),i0.ɵmpd(6144,i3.ɵSharedStylesHost,(null as any),[i3.ɵDomSharedStylesHost]),
39+
i0.ɵmpd(4608,i0.Testability,i0.Testability,[i0.NgZone]),i0.ɵmpd(4608,i3.Meta,
40+
i3.Meta,[i2.DOCUMENT]),i0.ɵmpd(4608,i3.Title,i3.Title,[i2.DOCUMENT]),
41+
i0.ɵmpd(4608,i6.AnimationBuilder,i5.ɵBrowserAnimationBuilder,[i0.RendererFactory2,
42+
i3.DOCUMENT]),i0.ɵmpd(512,i2.CommonModule,i2.CommonModule,([] as any[])),
43+
i0.ɵmpd(1024,i0.ErrorHandler,i3.ɵa,([] as any[])),i0.ɵmpd(1024,i0.APP_INITIALIZER,
44+
(p0_0:any) => {
45+
return [i3.ɵg(p0_0)];
46+
},[[2,i0.NgProbeToken]]),i0.ɵmpd(512,i0.ApplicationInitStatus,i0.ApplicationInitStatus,
47+
[[2,i0.APP_INITIALIZER]]),i0.ɵmpd(131584,i0.ɵg,i0.ɵg,[i0.NgZone,i0.ɵConsole,
48+
i0.Injector,i0.ErrorHandler,i0.ComponentFactoryResolver,i0.ApplicationInitStatus]),
49+
i0.ɵmpd(2048,i0.ApplicationRef,(null as any),[i0.ɵg]),i0.ɵmpd(512,i0.ApplicationModule,
50+
i0.ApplicationModule,[i0.ApplicationRef]),i0.ɵmpd(512,i3.BrowserModule,
51+
i3.BrowserModule,[[3,i3.BrowserModule]]),i0.ɵmpd(512,i5.BrowserAnimationsModule,
52+
i5.BrowserAnimationsModule,([] as any[])),i0.ɵmpd(512,i1.AppModule,i1.AppModule,
53+
([] as any[]))]);
54+
});
55+
const styles_Ng2Component:any[] = ([] as any[]);
56+
export const RenderType_Ng2Component:i0.RendererType2 = i0.ɵcrt({encapsulation:2,styles:styles_Ng2Component,
57+
data:{}});
58+
export function View_Ng2Component_0(_l:any):i0.ɵViewDefinition {
59+
return i0.ɵvid(0,[(_l()(),i0.ɵted((null as any),['\n '])),(_l()(),i0.ɵeld(0,(null as any),
60+
(null as any),1,'h2',([] as any[]),(null as any),(null as any),(null as any),
61+
(null as any),(null as any))),(_l()(),i0.ɵted((null as any),['ng2'])),(_l()(),
62+
i0.ɵted((null as any),['\n '])),(_l()(),i0.ɵeld(0,(null as any),(null as any),
63+
1,'button',([] as any[]),(null as any),[[(null as any),'click']],(_v,en,$event) => {
64+
var ad:boolean = true;
65+
var _co:i1.Ng2Component = _v.component;
66+
if (('click' === en)) {
67+
const pd_0:any = ((<any>_co.clickButton()) !== false);
68+
ad = (pd_0 && ad);
69+
}
70+
return ad;
71+
},(null as any),(null as any))),(_l()(),i0.ɵted((null as any),['Click Count: ',
72+
''])),(_l()(),i0.ɵted((null as any),['\n ']))],(null as any),(_ck,_v) => {
73+
var _co:i1.Ng2Component = _v.component;
74+
const currVal_0:any = _co.callCount;
75+
_ck(_v,5,0,currVal_0);
76+
});
77+
}
78+
export function View_Ng2Component_Host_0(_l:any):i0.ɵViewDefinition {
79+
return i0.ɵvid(0,[(_l()(),i0.ɵeld(0,(null as any),(null as any),1,'ng2',([] as any[]),
80+
(null as any),(null as any),(null as any),View_Ng2Component_0,RenderType_Ng2Component)),
81+
i0.ɵdid(49152,(null as any),0,i1.Ng2Component,([] as any[]),(null as any),(null as any))],
82+
(null as any),(null as any));
83+
}
84+
export const Ng2ComponentNgFactory:i0.ComponentFactory<i1.Ng2Component> = i0.ɵccf('ng2',
85+
i1.Ng2Component,View_Ng2Component_Host_0,{},{},([] as any[]));
86+
//# sourceMappingURL=data:application/json;base64,eyJmaWxlIjoiL3Vzci9sb2NhbC9nb29nbGUvaG9tZS9xaXlpL3Byb3RyYWN0b3IvdGVzdGFwcC91cGdyYWRlL2FwcC9kb3duZ3JhZGUvbmcyLm5nZmFjdG9yeS50cyIsInZlcnNpb24iOjMsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm5nOi8vL3Vzci9sb2NhbC9nb29nbGUvaG9tZS9xaXlpL3Byb3RyYWN0b3IvdGVzdGFwcC91cGdyYWRlL2FwcC9kb3duZ3JhZGUvbmcyLnRzIiwibmc6Ly8vdXNyL2xvY2FsL2dvb2dsZS9ob21lL3FpeWkvcHJvdHJhY3Rvci90ZXN0YXBwL3VwZ3JhZGUvYXBwL2Rvd25ncmFkZS9uZzIudHMuTmcyQ29tcG9uZW50Lmh0bWwiLCJuZzovLy91c3IvbG9jYWwvZ29vZ2xlL2hvbWUvcWl5aS9wcm90cmFjdG9yL3Rlc3RhcHAvdXBncmFkZS9hcHAvZG93bmdyYWRlL25nMi50cy5OZzJDb21wb25lbnRfSG9zdC5odG1sIl0sInNvdXJjZXNDb250ZW50IjpbIiAiLCJcbiAgICA8aDI+bmcyPC9oMj5cbiAgICA8YnV0dG9uIChjbGljayk9J2NsaWNrQnV0dG9uKCknPkNsaWNrIENvdW50OiB7e2NhbGxDb3VudH19PC9idXR0b24+XG4gICIsIjxuZzI+PC9uZzI+Il0sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztvQkNBQSwyQ0FDSTtNQUFBO01BQUEsOEJBQUksd0NBQVE7YUFBQSw0QkFDWjtNQUFBO1FBQUE7UUFBQTtRQUFRO1VBQUE7VUFBQTtRQUFBO1FBQVI7TUFBQSxnQ0FBZ0M7TUFBQSxNQUFtQzs7SUFBbkM7SUFBQTs7OztvQkNGcEM7TUFBQTthQUFBOzs7OyJ9

‎testapp/upgrade/app/downgrade/ng2.ngsummary.json

+1
Large diffs are not rendered by default.

‎testapp/upgrade/app/downgrade/ng2.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as angular from 'angular';
2+
import { NgModule , Component } from '@angular/core';
3+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4+
import { downgradeComponent } from '@angular/upgrade/static';
5+
6+
import { ng1module } from './ng1';
7+
8+
@Component({
9+
selector: 'ng2',
10+
template: `
11+
<h2>ng2</h2>
12+
<button (click)='clickButton()'>Click Count: {{callCount}}</button>
13+
`
14+
})
15+
export class Ng2Component {
16+
callCount: number = 0;
17+
clickButton = () => {
18+
setTimeout(() => {
19+
this.callCount++;
20+
}, 1000);
21+
};
22+
}
23+
24+
@NgModule({
25+
imports: [
26+
BrowserAnimationsModule,
27+
],
28+
declarations: [
29+
Ng2Component,
30+
],
31+
entryComponents: [
32+
Ng2Component
33+
]
34+
})
35+
export class AppModule {
36+
ngDoBootstrap() {}
37+
}
38+
39+
40+
41+
// Register the Angular 2 component with the Angular 1 module.
42+
ng1module.directive(
43+
'ng2', // lowerCamel when registering.
44+
// propagateDigest: false will detach the digest cycle from AngularJS from
45+
// propagating into the Angular (2+) CD.
46+
downgradeComponent({component: Ng2Component, propagateDigest: false}));
47+

‎testapp/upgrade/index.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
System.import('systemjs.config.js').then(function () {
2323
if (window.location.search.indexOf('no_static') != -1) {
2424
System.import('app/no_static/main');
25-
} else {
25+
}
26+
else if (window.location.search.indexOf('downgrade') != -1) {
27+
System.import('app/downgrade/main');
28+
}
29+
else {
2630
System.import('app/main');
2731
}
2832
}).catch(function(err) {

‎testapp/upgrade/systemjs.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
1919
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
2020
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
21+
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
22+
'@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
23+
'@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
2124
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
2225
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
2326
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',

0 commit comments

Comments
 (0)
This repository has been archived.