加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用templateUrl的angular2动态组件的“无法读取url”错误

发布时间:2020-12-17 17:17:13 所属栏目:安全 来源:网络整理
导读:试图修改灵魂 from here. 它工作正常,但是如果你将模板更改为组件中的templateUrl,那应该动态加载,你会收到一个错误:“没有提供ResourceLoader实现.无法读取url …”. @Component({ selector: 'string-editor',templateUrl: 'app/parts/string.html',//usin
试图修改灵魂 from here.
它工作正常,但是如果你将模板更改为组件中的templateUrl,那应该动态加载,你会收到一个错误:“没有提供ResourceLoader实现.无法读取url …”.

@Component({
    selector: 'string-editor',templateUrl: 'app/parts/string.html',//using template URL instead of inline template here
})
export class StringEditor { ... }

关于plunker的实例.任何想法如何解决这个问题?

解决方法

不要使用COMPILER_PROVIDERS,因为它会覆盖ResourceLoader.

对于动态加载,请使用Compule from core package(实际上与RuntimeCompiler相同):

@Inject(Compiler) protected compiler: Compiler

并将ApplicationModule作为导入添加到模块中:

imports: [ 
    ApplicationModule,BrowserModule,DynamicModule.forRoot() // singletons
],

Plunker

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读