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

前端之家收集整理的这篇文章主要介绍了使用templateUrl的angular2动态组件的“无法读取url”错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
试图修改灵魂 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

猜你在找的Angularjs相关文章