【发布时间】:2017-12-19 22:08:02
【问题描述】:
我正在尝试让 ng-2 引导模式在我的代码中工作。我已经让 ng2-bootstrap 工具提示可以正常工作,但是模式给我带来了很多麻烦。我已经检查了所有相关的 github 页面和 stackover flow 问题,但我仍然无法弄清楚。这是我的设置:
我的 router.html(模板)
...
<div class="modal fade" alertModal #staticModal="alert-modal" role="dialog" aria-labelledby="alertModal">`
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="alertModalTitle"></h3>
</div>
<div class="modal-body" id="alertModalBody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
...
我的 app.module.ts 的一部分:
import { TooltipModule,ModalModule } from 'ng2-bootstrap';
@NgModule({
imports: [ModalModule.forRoot(), TooltipModule.forRoot(), ...],
declarations: [AppComponent,...],
bootstrap: [AppComponent],
providers: [...]
})
export class AppModule {}
我的 app.component.ts 使用了这个模式:
import { Component, OnInit, Inject, ViewChild, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { MultistepService, StepDirection } from '../service/multistep.service';
import { ModalDirective } from 'ng2-bootstrap';
@Component({
selector: 'my-app',
host: {
'class': 'container-fluid'
},
templateUrl: './app/component/router.html'
})
export class AppComponent implements OnInit {
@ViewChild('staticModal')
private alertModal:ModalDirective;
<some methods here>
}
这是我得到的错误:
Template parse errors:
There is no directive with "exportAs" set to "alert-modal"
我有什么遗漏吗?提前致谢!
【问题讨论】:
-
他们将其设置为不等于某物,而是等于
exportAs变量github.com/valor-software/ngx-bootstrap/blob/development/src/… 您可以考虑#staticModal="bs-modal",例如#something="exportAsVar"。您可以随意调用#variable,但它应该始终等于bs-modal,即#myMegaVariable="bs-modal",然后您可以在模板中使用myMegaVariable.show()
标签: angular typescript angular-ui-bootstrap ng2-bootstrap