ng2-bootstrap - 模型 - 从组件打开
ng2-bootstrap - model - Open from the component
我想从组件打开对话框:
<!-- Large modal -->
<button class="btn btn-primary" (click)="lgModal.show()">Large modal</button>
<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Large modal</h4>
</div>
<div class="modal-body">
...
</div>
</div>
</div>
</div>
bsModel 的 lgModal.show() 打开对话框,如何从组件打开对话框:
import {Component} from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
// todo: change to ng2-bootstrap
import {MODAL_DIRECTVES, BS_VIEW_PROVIDERS} from '../../../ng2-bootstrap';
// webpack html imports
let template = require('./modal-demo.html');
@Component({
selector: 'modal-demo',
directives: [MODAL_DIRECTVES, CORE_DIRECTIVES],
viewProviders:[BS_VIEW_PROVIDERS],
template: template
})
export class ModalDemoComponent {
}
我不能从组件中执行类似 lgModal.show() 的操作吗?
在组件的 class 实现中添加:
@ViewChild('lgModal') bgModel;
然后您可以在 class 和 this.bgModel
中引用它。
祝你好运
我想从组件打开对话框:
<!-- Large modal -->
<button class="btn btn-primary" (click)="lgModal.show()">Large modal</button>
<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Large modal</h4>
</div>
<div class="modal-body">
...
</div>
</div>
</div>
</div>
bsModel 的 lgModal.show() 打开对话框,如何从组件打开对话框:
import {Component} from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
// todo: change to ng2-bootstrap
import {MODAL_DIRECTVES, BS_VIEW_PROVIDERS} from '../../../ng2-bootstrap';
// webpack html imports
let template = require('./modal-demo.html');
@Component({
selector: 'modal-demo',
directives: [MODAL_DIRECTVES, CORE_DIRECTIVES],
viewProviders:[BS_VIEW_PROVIDERS],
template: template
})
export class ModalDemoComponent {
}
我不能从组件中执行类似 lgModal.show() 的操作吗?
在组件的 class 实现中添加:
@ViewChild('lgModal') bgModel;
然后您可以在 class 和 this.bgModel
中引用它。
祝你好运