2016-09-28 5 views
0

角度1のコンポーネントを再利用するために、angle2プロジェクトを開始します。私はこのplunkr http://plnkr.co/edit/yMjghOFhFWuY8G1fVIEgに基づいて、セットアップに私のプロジェクトを試してみましたが、私は私のアプリを実行しようとしたとき、私はこのエラーを得た:ハイブリッドangle1 + 2アプリケーションのエラー:未知のエラー:Angular2アプリのNgModuleなしでUpgradeAdapterをインスタンス化できません

Uncaught Error: UpgradeAdapter cannot be instantiated without an NgModule of the Angular 2 app. 

plunkrただのNG2モジュールなしでアップグレードアダプタをインスタンス化して、私は理由を理解していませんそれは私のために働かなかった。 plunkrが使っているangular2のバージョンがわかりませんが、私はバージョン2.0.0を使っています。

答えて

0

明らかに、角度2.0.0では、UpgradeAdapterコンストラクタにNgModuleを渡す必要があります。

var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module)); 
var module = angular.module('myExample', []); 

module.directive('greet', function() { 
return { 
scope: {salutation: '=', name: '='}, 
template: '{{salutation}} {{name}}! - <span ng-transclude></span>' 
}; 
}); 

module.directive('ng2', adapter.downgradeNg2Component(Ng2)); 

@Component({ 
    selector: 'ng2', 
    template: 'ng2 template: <greet salutation="Hello" [name]="world">text</greet>' 
}) 
class Ng2 { 
} 

@NgModule({ 
declarations: [Ng2, adapter.upgradeNg1Component('greet')], 
imports: [BrowserModule] 
}) 
class MyNg2Module { 
} 

document.body.innerHTML = '<ng2></ng2>'; 

adapter.bootstrap(document.body, ['myExample']).ready(function() { 
    expect(document.body.textContent).toEqual("ng2 template: Hello world! - text"); 
}); 
+0

あなたが他の場所で、あなたのコード内でこれを持っていたかどうかわからないけど、あなたはまた、 '「角度/コア@」からインポート{forwardRef}を必要とする;':私は作品の角度/更新@から次のコードスニペットを掘っ –

関連する問題