2015-10-14 42 views
0

我試圖整合的角度1.x的應用程序內的角2.0組件(播放/學習提出...)整合角度1.x的內部角2.0 - 升級模塊

現在,我看到它可以通過查看Angular2 upgrade module來完成:

import {Component, View, Inject, EventEmitter} from 'angular2/angular2'; 
    import {createUpgradeModule, UpgradeModule} from 'upgrade/upgrade'; 

    export function main() { 
     describe('upgrade: ng1 to ng2',() => { 
     it('should have angular 1 loaded',() => expect(angular.version.major).toBe(1)); 

     it('should instantiate ng2 in ng1 template and project content', 
      inject([AsyncTestCompleter], (async) => { 
      var Ng2 = Component({selector: 'ng2'}) 
          .View({template: `{{ 'NG2' }}(<ng-content></ng-content>)`}) 
          .Class({constructor: function() {}}); 

      var element = html("<div>{{ 'ng1[' }}<ng2>~{{ 'ng-content' }}~</ng2>{{ ']' }}</div>"); 

      var upgradeModule: UpgradeModule = createUpgradeModule(); 
      upgradeModule.importNg2Component(Ng2); 
      upgradeModule.bootstrap(element).ready(() => { 
       expect(document.body.textContent).toEqual("ng1[NG2(~ng-content~)]"); 
       async.done(); 
      }); 
      })); 
... continue tests here ... 

我創建了打字稿+ SystemJS + JSPM的角度1.x的應用程序,並使用jspm install angular2

現在安裝角2.0,我可以使用Angular2導入import {Component} from 'angular2/angular2'(例如le),但我無法在Angular2的代碼中找到升級模塊(我想做import {createUpgradeModule, UpgradeModule} from 'upgrade/upgrade',與我在測試中發現的類似)。

它是在一個單獨的包?我應該手動安裝嗎?

編輯

的解決方案(現在),應該是:

  1. 使用自定義生成,請參閱here

  2. 採取實際的模塊你的項目和導入(這是我的首選解決方案)

    編輯22.11.15:

從alpha 46起,升級模塊是公開的。爲了使用它,不需要任何更多的黑客!

+1

我認爲你可能正在尋找[這一行](https://github.com/angular/angular/blob/master/test-main.js#L18)。我無法在我的項目中找到這樣的路徑,所以也許它沒有被分配等等。但是,你可以做的是叉角回購,建立它,你會發現該目錄,所以你可以複製並粘貼到您的項目。 –

回答

1

我已經做了一些POC工作圍繞這一點,這裏是一個工作方法:

這裏的關鍵是upgradeAdaptor

import {bootstrap,UpgradeAdapter} from 'angular2/angular2'; 
import {SomeA2Component} from './some/path'; 

declare var angular:any; 

var adapter: UpgradeAdapter = new UpgradeAdapter(); 
angular.module('app').directive('SomeA2Component', adapter.downgradeNg2Component(MyA2Component)); 
adapter.bootstrap(document.body, ['app']); 

我這兒也有一個工作示例:http://www.syntaxsuccess.com/viewarticle/upgrading-angular-1.x-to-2.0

+0

謝謝。至於alpha 46升級模塊是公共的,不需要解決方法。很好的博客文章! –