10

ng2 コンポーネント内で使用される ng1 コンポーネントをアップグレードしたいと考えています。

テンプレート文字列だけを使用して ng1 コンポーネントをアップグレードすると、機能します。ただし、代わりに templateUrl の使用に切り替えると、アプリがクラッシュし、次のエラーが表示されます。

angular.js:13920 Error: loading directive templates asynchronously is not supported
at RemoteUrlComponent.UpgradeComponent.compileTemplate (upgrade-static.umd.js:720)
at RemoteUrlComponent.UpgradeComponent (upgrade-static.umd.js:521)
at new RemoteUrlComponent (remote-url.component.ts:11)
at new Wrapper_RemoteUrlComponent (wrapper.ngfactory.js:7)
at View_AppComponent1.createInternal (component.ngfactory.js:73)
at View_AppComponent1.AppView.create (core.umd.js:12262)
at TemplateRef_.createEmbeddedView (core.umd.js:9320)
at ViewContainerRef_.createEmbeddedView (core.umd.js:9552)
at eval (common.umd.js:1670)
at DefaultIterableDiffer.forEachOperation (core.umd.js:4653)

ここに私の問題を示すプランクがあります:

https://plnkr.co/edit/2fXvfc?p=info

Angular 1 -> 2 アップグレード ガイドに従っていますが、このコードは機能するはずです。なぜ機能しないのかよくわかりません。

4

9 に答える 9

8

この問題に対する非常に安価な解決策を見つけました。

template: require('./remote-url.component.html')の代わりに使用するだけでtemplateUrl: './remote-url.component.html'、問題なく動作するはずです。

于 2017-01-03T12:31:40.267 に答える