2016-09-20 119 views
3

隨着Angular 2.0的最終版本,我們的應用程序需要進行遷移。我首先從RC4移植到RC5,然後再移植到最終。我遵循從barbarianmeetscoding-updating-your-angular-2-app-from-rc4-to-rc5-a-practical-guideangular.io - rc4-to-rc5.html的遷移步驟。Angular 2 RC4到RC5的遷移

我們的應用程序是一個具有100個奇數組件的大型應用程序。我的問題是,爲了成功遷移,我應該一次對所有組件進行更改還是可以一次將它們組成一個組件?

我已經對main.ts,package.json,app.ts和app.module.ts進行了必要的修改。首先,我將組件指令和提供程序從app.ts移至app.module,並對app.routes進行了必要的更改。 但我得到以下錯誤 Error screenshot

但是,在提到的組件中沒有明確使用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 { } 
+0

你檢查[這](https://github.com/angular/angular/issues/10612 )出來。看起來類似於你正在處理的事情 – Bean0341

回答

0

去過那裏。這非常痛苦,但從RC5移植到最終版本更容易。也許你應該考慮直接進入決賽,而不是RC5?關於你的問題:這取決於你的應用的整體架構。有時候,一個接一個的組件會更容易。另一方面,組件之間的依賴關係可能如此重要,以至於您需要立即進行所有更改。

我不是100%確定從哪裏得到的錯誤,但可能是因爲您在app.module中導入和聲明時出錯。應該去進口的東西去聲明或其他方式。 toString()是返回字符串表示形式this對象的框架的方法。

+0

所以即使我不把指令從我的所有組件移到app.module,我的應用程序仍然應該運行,因爲它提到現在所有的指令和管道都會被掛起。對? – user3344978

+0

是的。但是你應該考慮它,因爲從RC6開始發佈它就是必需的。 –

+0

從RC6開始發佈將需要我將所有指令,管道和服務移動到app.module中?在我們的應用程序中,我們有100個奇數組件和大約15個服務那麼,我應該將每個指令和服務移動到app.module中嗎?或者我應該只移動最常用的那些? – user3344978

0

在我升級到2.0.0,我發現最簡單的:

  1. 採用了棱角分明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 [email protected] 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)