angularjs - 吴升级 : Unable to use templateUrl when upgrading Angular1 components

标签 angularjs angular ng-upgrade

我想升级一个 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/

相关文章:

html - ionic 2 : ion-content doesnt scroll up on keyboard

Angular 5.x 页面加载或模块本身的初始化需要更长的时间

angularjs - 同时运行 Angular 和 AngularJS 框架

javascript - 将 angularjs 服务注入(inject) Angular

javascript - 将 AngularJs javascript 文件包含到 Angular cli 中

angularjs - 增加 ngif-tag 之外的范围?

javascript - 在 ng-repeat 中突出显示一行的更有效方法? ... Angular 方式

javascript - 如何在更改值后立即发布作用域变量?

javascript - 从 ui-router 获取 templateUrl

javascript - 使用 jquery 将字符串转换为 UTC 时间