【问题标题】:Angular 2 RC4 to RC5 migrationAngular 2 RC4 到 RC5 的迁移
【发布时间】:2023-03-17 09:55:01
【问题描述】:

随着 Angular 2.0 的最终发布,我们的应用程序需要进行迁移。我首先从 RC4 迁移到 RC5,然后再迁移到 final。我遵循了barbarianmeetscoding-updating-your-angular-2-app-from-rc4-to-rc5-a-practical-guideangular.io - rc4-to-rc5.html 的迁移步骤。

我们的应用程序是一个包含 100 多个组件的大型应用程序。我的问题是,为了成功迁移,我应该一次更改所有组件还是一次只更改一个组件?

我对 main.ts、package.json、app.ts 进行了必要的更改并引入了 app.module.ts。首先,我将组件指令和提供程序从 app.ts 移至 app.module,并在 app.routes 中进行了必要的更改。 但我收到以下错误

但在提到的组件中没有明确使用 toString()。

app.module.ts

import { NgModule, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import * as ngCore from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { HttpModule} from '@angular/http';
import {HTTP_PROVIDERS} from '@angular/http';
import {routing} from './app.routes';
import { App}  from './app';
import {LocationStrategy, HashLocationStrategy} from  '@angular/common';
import {HttpService}  from '../service/http/httpService';
import {Button} from '../components/button';
import {Checkbox} from '../components/checkbox';
import {PipeSafe} from "../pipe/pipe-safe";
import {OrderBy} from "../pipe/orderby";
import {Number} from '../pipe/number';
@NgModule({
    imports: [
       BrowserModule,
       FormsModule,
       HttpModule,
       routing
    ],
    declarations: [
       App,
       PipeSafe,
       OrderBy,
       Number
    ],
    providers: [
       ngCore.provide(LocationStrategy, {useClass: HashLocationStrategy}),
       ngCore.provide('TemplateComponents', { useValue: {
          'button': Button,
          'checkbox': Checkbox,

       }}),
    HttpService
    ],
    bootstrap:    [ App ],
    schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
  })
  export class AppModule { }

【问题讨论】:

  • 您检查过this。看起来与您正在处理的相似

标签: angular


【解决方案1】:

去过那里。这很痛苦,但令人欣慰的是,从 RC5 迁移到最终版本要容易得多。也许您还应该考虑直接迁移到决赛,而不是 RC5?关于您的问题:这取决于您的应用程序的整体架构。有时一个组件一个组件会更容易。另一方面,组件之间的依赖关系可能非常重要,以至于您需要立即进行所有更改。

我不能 100% 确定您从哪里得到错误,但可能是因为您在 app.module 中的导入和声明中有错误。应该去进口的东西去申报或相反。 toString() 是框架的方法,它返回 this 对象的字符串表示形式。

【讨论】:

  • 因此,即使我没有将所有组件中的指令移动到 app.module,我的应用程序仍应运行,因为它提到现在所有指令和管道都将被提升。对吗?
  • 没错。但是您应该考虑它,因为从 RC6 开始的版本中需要它。
  • 从 RC6 开始的版本将要求我将所有指令、管道和服务移动到 app.module 中?在我们的应用程序中,我们有 100 个奇怪的组件和大约 15 个服务。那么,我应该将每个指令和服务都移到 app.module 中吗?还是应该只移动最常共享的那些?
【解决方案2】:

在升级到2.0.0 时,我发现最简单的方法是:

  1. 使用 Angular CLI 创建一个简单的、有一定代表性的2.0.0-rc.4 应用程序;然后,

  2. 将应用程序升级到2.0.0

我使用不同版本的 Angular CLI 来为迁移的两个阶段获取正确的依赖项和配置文件(包括 webpack)。您需要尝试使用 Angular CLI 来找到生成 Angular 2.0.0-rc.4 应用程序的版本);您可以使用最新版本来生成最终应用程序。

然后我将我的简单应用程序的2.0.0 升级所需的一组更改应用于我的整个实际应用程序;并测试了每个组件,并根据需要进行小幅修正。

这是我在升级过程中遇到的一些问题。如果您按照我上面的建议进行操作,您会(希望)跳过其中的一些。

Module not found: Error: Can't resolve 'hammerjs'

Cannot find module './models/config'

"The package rxjs@5.0.0-beta.11 does not satisfy its siblings' peerDependencies requirements!"

TypeError: Cannot read property 'directoryExists' of undefined

@angular/forms Generic type 'Type<T>' requires 1 type argument(s)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多