laravel – Angular 2覆盖组件

前端之家收集整理的这篇文章主要介绍了laravel – Angular 2覆盖组件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我来自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

core.template.html(原创)

<div>
    <p> This is a core component's template</p>
    <button>Click me! </button>
</div>

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>

希望我已经清楚地说明了我面临的问题.

@R_404_323@

覆盖组件的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 {}

猜你在找的Angularjs相关文章