问题描述
我正在考虑将angular 1.4应用程序迁移到angular 2,我想知道是否有可能像我们使用$ provide.decorator(例如).
I am considering migrating an angular 1.4 application to angular 2 and I wonder if it will be possible to override components' template like we do in angular1 using $provide.decorator (like Can you override specific templates in AngularUI Bootstrap?).
我正在寻找类似 TestComponentBuilder.overrideTemplate
的东西,但是用于非测试场景. Angular2是否具有类似的功能?
I am looking for something like TestComponentBuilder.overrideTemplate
but for a non-testing scenario. Does Angular2 comes with something similar?
推荐答案
从stackoverflow .主要思想是您可以编写自己的组件并扩展第三方组件.
Check out this answer from stackoverflow Override/extend third-party component's template. The main idea is you can write your own component and extend third party component.
import {component} from 'angular2/core';
import {thirdPartyClass} from 'example/example';
@Component({
selector: 'my-selector',
template: '<div>my template</div>'
})
export class MyOwnComponent extends thirdPartyClass {
constructor() {
super()
}
}
但是有缺点:
- 它仍将编译原始组件.
- 如果您使用的是此方法,请不要忘记导入任何用于thirdPartyClass模板.
-
是否在第三方依赖于该功能的第三方类中更新了功能在模板上,您需要手工进行更新.
- It will still compile original component.
- If you are using this method, don't forget to import any pipes thatare used in the thirdPartyClass template.
If the functionality is updated in the thirdPartyClass that dependsupon the template, you'll need to update by hand.
订阅此 Github问题进行进一步的更新.
Subscribe to this Github Issue for further updates.
这篇关于Angular2:如何覆盖组件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!