我想升级一个 ng1 组件以在 ng2 组件中使用。
如果我只使用要升级的 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 升级指南进行操作,看来这段代码应该可以工作。我不太确定为什么它不起作用。
最佳答案
我找到了一个非常便宜的解决方案。
只需使用 template: require('./remote-url.component.html')
而不是 templateUrl: './remote-url.component.html'
它应该工作得很好!
关于angularjs - 吴升级 : Unable to use templateUrl when upgrading Angular1 components,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41348403/