我正在尝试在 Angular 2 中本地扩展现有的工作组件。我没有得到任何真正有用的指示来说明问题是什么,没有错误等。
所以我修改了一个现有的 plunker ( https://plnkr.co/edit/8x34JbEhYdVms4iYLRvM?p=preview ),它有一个 ngx-modal 工作的例子。
(我正在尝试正确使用这种技术,所以它是 ngx-modal 并不重要,它恰好是我发现一个很好的 plunker 的技术。)
我添加了一个扩展其他组件的新组件...
ngx-modal.component.ts
//Extend and wrap NGX MODAL
import { Component } from '@angular/core';
import { ModalModule } from "ngx-modal";
@Component({
selector: 'ext-ngx-modal',
template: `<ng-content></ng-content>`,
})
export class NgxModalComponent extends ModalModule {
constructor() {
super();
}
}
我用app.ts包装了现有的模式
<ext-ngx-modal>
<modal #myModal>
<modal-header>
<h1>Modal header</h1>
</modal-header>
<modal-content>
Hello Modal!
</modal-content>
<modal-footer>
<button class="btn btn-primary"(click)="myModal.close()">close</button>
</modal-footer>
</modal>
并注册了组件:
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {ModalModule} from "ngx-modal";
import {NgxModalComponent} from "ngx-modal.component"
@Component({
ETC...
@NgModule({
imports: [ BrowserModule,ModalModule ],
declarations: [ App, NgxModalComponent ],
exports: [ NgxModalComponent ],
bootstrap: [ App ]
})
在此之后,plunker 不会运行......!