Skip to content

Commit 0386e8c

Browse files
still problems wiith the $injector when calling the super to upgrade a component
1 parent f1a36e7 commit 0386e8c

File tree

4 files changed

+70
-16
lines changed

4 files changed

+70
-16
lines changed

ng1/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
.module('demo', [])
55
.component('ng1AppComponent', {
66
template: '<div>Hi</div>',
7-
controller: function (sessionService) {
8-
console.log(sessionService.get())
7+
controller: function () {
8+
console.log('hi from ng1AppComponent')
99
}
1010
})
1111
.component('ng1FooComponent', {

src/app/app.module.ts

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,58 @@
1-
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
31

4-
import { AppComponent } from './app.component';
2+
import { NgModule, Inject, Injectable, Component, Directive, Injector, ElementRef } from '@angular/core'
3+
import { BrowserModule } from '@angular/platform-browser'
4+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
5+
import { UpgradeModule, downgradeInjectable, UpgradeComponent } from '@angular/upgrade/static';
6+
7+
// import { AppComponent } from './app.component';
8+
9+
// @NgModule({
10+
// declarations: [
11+
// AppComponent
12+
// ],
13+
// imports: [
14+
// BrowserModule
15+
// ],
16+
// providers: [],
17+
// bootstrap: [AppComponent]
18+
// })
19+
// export class AppModule { }
20+
21+
@Directive({
22+
// tslint:disable-next-line:directive-selector
23+
selector: 'ng1-foo-component'
24+
})
25+
export class Ng1FooDirective extends UpgradeComponent {
26+
constructor(elementRef: ElementRef, injector: Injector) {
27+
super('ng1FooComponent', elementRef, injector);
28+
}
29+
}
30+
31+
32+
@Component({
33+
// tslint:disable-next-line:component-selector
34+
selector: 'root-component',
35+
template: '<div>Root</div><ng1-foo-component></ng1-foo-component>'
36+
})
37+
export class RootComponent {
38+
constructor() {
39+
console.log('RootComponent')
40+
}
41+
}
42+
543

644
@NgModule({
7-
declarations: [
8-
AppComponent
9-
],
10-
imports: [
11-
BrowserModule
12-
],
13-
providers: [],
14-
bootstrap: [AppComponent]
45+
imports: [ BrowserModule, UpgradeModule ],
46+
declarations: [ RootComponent, Ng1FooDirective ],
47+
bootstrap: [ RootComponent ]
1548
})
16-
export class AppModule { }
49+
export class AppModule {
50+
constructor(private upgrade: UpgradeModule) {
51+
}
52+
53+
ngDoBootstrap() {
54+
// this.upgrade.bootstrap(document.body, ['demo'], { strictDi: true });
55+
}
56+
}
57+
58+

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<link rel="icon" type="image/x-icon" href="favicon.ico">
1010
</head>
1111
<body>
12-
<app-root></app-root>
12+
<root-component>loading...</root-component>
1313
</body>
1414
</html>

src/main.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
33

44
import { AppModule } from './app/app.module';
55
import { environment } from './environments/environment';
6+
import { UpgradeModule } from '@angular/upgrade/static';
67

78
if (environment.production) {
89
enableProdMode();
910
}
1011

11-
platformBrowserDynamic().bootstrapModule(AppModule);
12+
// platformBrowserDynamic().bootstrapModule(AppModule);
13+
14+
platformBrowserDynamic().bootstrapModule(AppModule)
15+
.then(ref => {
16+
// Once Angular bootstrap is complete then we bootstrap the AngularJS module
17+
const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
18+
19+
upgrade.bootstrap(document.body, ['demo']);
20+
});
21+
// platformBrowserDynamic().bootstrapModule(AppModule);
22+
23+

0 commit comments

Comments
 (0)