加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – $scope的提供者!在角度2应用程序中使用角度1指令

发布时间:2020-12-17 07:01:38 所属栏目:安全 来源:网络整理
导读:我有一个使用angular-cli构建的角度2应用程序,我需要在我的一个组件中使用角度1指令(从不同的应用程序重用它).我按照以下步骤操作: https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-angular-1-component-directives-from-angular-2-code 但
我有一个使用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 { }

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

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

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

<h2>Windstorm details!</h2>

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

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

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

解决方法

看来你的引导逻辑不正确.

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

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

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

enter image description here

…确保ng2注射器具有ng1所需的所有提供者.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读