“无法读取网址"使用templateUrl的angular2动态组件的错误 [英] "Can't read the url" error for angular2 dynamic components with templateUrl

查看:87
本文介绍了“无法读取网址"使用templateUrl的angular2动态组件的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图修改灵魂

Tried to modify soultion from here. It works fine, but if you change template to templateUrl in component, that should load dynamically, you get an error: "No ResourceLoader implementation has been provided. Can't read the url ...".

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

plunker 上的实时示例.有任何解决方法的想法吗?

Live example on plunker. Any ideas how to fix this?

推荐答案

请勿使用COMPILER_PROVIDERS,因为它会覆盖ResourceLoader.

Don't use COMPILER_PROVIDERS, because it overrides the ResourceLoader.

对于动态加载,请使用核心软件包中的Compiler(实际上与RuntimeCompiler相同):

For dynamic loading use the Compiler from core package (which is actually the same as RuntimeCompiler):

@Inject(Compiler) protected compiler: Compiler

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

and add the ApplicationModule as import in your module:

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

柱塞

这篇关于“无法读取网址"使用templateUrl的angular2动态组件的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆