Pal*_*diN 5 overriding modular laravel angular-template angular
我来自Laravel世界,对Angular 2世界有点新意,我很难弄明白:
是否可以覆盖Angular 2中的组件或模板,就像我们用来覆盖Laravel中供应商/自定义包的视图一样?
这是一个虚拟文件夹结构,可能表达我的意思:
|-resources
|-assets
|-typescript
|-core
|-core.component.ts //overridded core component and template
|-core.template.html
|-Modules
|-Core
|-Resources
|-assets
|-typescript
|-core
|-core.component.ts //main module component and template
|-core.template.html
Run Code Online (Sandbox Code Playgroud)
core.template.html(原创)
<div>
<p> This is a core component's template</p>
<button>Click me! </button>
</div>
Run Code Online (Sandbox Code Playgroud)
core.template.html(重写)
<div>
<p> This is a overridden core component's template</p>
<p> Removed the button and overridden with p-tag </p>
</div>
Run Code Online (Sandbox Code Playgroud)
希望我已经清楚地说明了我面临的问题.
重写组件的 teamplete 是 Angular 2 的一个未解决的问题
信息来自: https: //github.com/angular/angular/issues/11144
但现在您可以使用 Reflect 来更改组件的元数据。
import {Component} from 'angular2/core'
@Component({
selector: 'thirdpartycomp',
providers: [],
template: `Hello From Third Party App!`,
directives: []
})
export class ThirdParty{}
annotations = Reflect.getMetadata('annotations', Thing);
for (let i = 0; i < annotations.length; i += 1) {
if (annotations[i].constructor.name === 'ComponentMetadata') {
annotations[i].template = 'Hello From My App!';
break;
}
}
@Component({
selector: 'my-app',
directives: [ThirdParty],
template: `<thirdpartycomp></thirdpartycomp>`,
})
export class App {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1693 次 |
| 最近记录: |