$ scope的提供商!在角度2应用程序中使用角度1指令时出错

ral*_*uca 8 angularjs ng-upgrade angular

我有一个使用angular-cli构建的角度2应用程序,我需要在我的一个组件中使用角度1指令(从不同的应用程序重用它).我按照以下步骤操作:

https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-angular-1-component-directives-from-angular-2-code

但现在我遇到了这个错误,无法超越它.我正在使用angular2.0.2(我设法在过去使用beta版本构建了一个混合应用程序,但它是一个angular1应用程序,我使用角度2组件与适配器的降级功能).

在我的app.module.ts中我有:

import { UpgradeAdapter } from '@angular/upgrade';
const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));

const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');

@NgModule({
    imports:      [
        BrowserModule,
        ...
    ],
    declarations: [
      ...       
     HeroDetail
     ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

我的hero-detail.component.ts看起来像这样:

export const heroDetail = {
  templateUrl: 'hero-detail.html',
  controller: function() {
  }
};
Run Code Online (Sandbox Code Playgroud)

而我的hero-detail.html看起来像这样:

   <h2>Windstorm details!</h2>
Run Code Online (Sandbox Code Playgroud)

我只是通过添加模板尝试在另一个角度2组件中使用该指令:

当我运行服务时,应用程序编译正常,但当我尝试加载页面时,我得到上述错误.

关于如何向前推进的任何建议?

Dem*_*ton 5

看来您的引导逻辑不正确。

实际上不是很明显,请确保:

  • 您不使用 引导任何ng2组件@NgModule({bootstrap:[ ... ]})ngDoBootstrap() { }相反,您的主模块中应该有空方法。
  • 根模板是ng1模板。也就是说,index.html您应该只有ng1组件或降级的ng2组件。您可以将ng2组件作为 root,但您需要先将其降级。

官方升级指南包含 DOM 结构的示例:

在此输入图像描述

...这确保ng2注入器拥有ng1所需的所有提供程序。