我已经为这个问题苦苦挣扎了很长一段时间了。也许有人可以给我一些提示或答案。
我正在尝试按照角度升级指南设置 ng1-ng2 Hybrid 应用程序
https://angular.io/docs/ts/latest/guide/upgrade.html
如果我这样引导:
// app.module.ts
@NgModule({
imports: [
RouterModule.forRoot(...)
BrowserModule,
UpgradeModule
],
entryComponent: [ AppComponent ]
})
export class AppModule {
ngDoBootstrap() {}
}
// main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['app'], {strictDi: true});
});
angular2 路由器以某种方式无法正确设置(从不调用应该处理 Url)
如果我使用 angular2 组件进行引导,我会遇到 $injector 未定义的问题。
我创建了这个 plnkr 来重新创建问题:(编辑:新 plnkr)
https://plnkr.co/edit/mUvt7miMrOEyTyEk8ooX?p=preview
TypeError: Cannot read property 'get' of undefined
at useFactory (https://run.plnkr.co/lohIgMlIbiNzGEHg/src/app.ts!transpiled:65:45)
at AppModuleInjector.get (/AppModule/module.ngfactory.js:140:73)
at AppModuleInjector.getInternal (/AppModule/module.ngfactory.js:192:50)
at AppModuleInjector.NgModuleInjector.get (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:8918:48)
at CompiledTemplate.proxyViewClass.AppView.injectorGet (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:12319:49)
at CompiledTemplate.proxyViewClass.DebugAppView.injectorGet (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:12699:53)
at CompiledTemplate.proxyViewClass.View_RootComponent_Host0.createInternal (/AppModule/RootComponent/host.ngfactory.js:15:65)
at CompiledTemplate.proxyViewClass.AppView.createHostView (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:12275:25)
at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:12683:56)
at ComponentFactory.create (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:7710:29)
at ApplicationRef_.bootstrap (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:8677:61)
at eval (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:8506:93)
at Array.forEach (native)
at PlatformRef_._moduleDoBootstrap (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:8506:46)
at eval (https://npmcdn.com/@angular/core@2.4.1/bundles/core.umd.js:8458:31)
把它们加起来:
如果我使用 angular1 组件作为根并将 angular2“rootComponent”标记为 entyComponent,则 angular2 路由器不会被初始化。(https://angular.io/docs/ts/latest/guide/upgrade.html#!#bootstrapping-混合应用)
如果我使用和 angular2 组件作为根,我会得到 $injector 问题(如 plnkr 所示),仅当“初始路由(/登录)”是 angular2 路由时。如果我从 angular1 路由器开始,然后更改为 angular2 路由(/登录),一切正常。(https://angular.io/docs/ts/latest/guide/upgrade.html#!#dividing-routes-between-angular-and-angularjs)
我会非常感谢任何建议。
非常感谢你提前罗宾