简体   繁体   English

ngx-bootstrap错误TypeError:_co.openModal不是函数

[英]ngx-bootstrap ERROR TypeError: _co.openModal is not a function

I'm new with ngx-bootstrap, and i try to make modal from this site : https://valor-software.com/ngx-bootstrap/#/modals 我是ngx-bootstrap的新手,我尝试从此站点制作模式: https ://valor-software.com/ngx-bootstrap/#/modals

this i got this error: ERROR TypeError: _co.openModal is not a function 这我得到这个错误:错误TypeError:_co.openModal不是一个函数

here is some snippets 这是一些片段

 //app.component.ts file import { Component } from '@angular/core'; import { TemplateRef } from '@angular/core'; import { BsModalService } from 'ngx-bootstrap/modal'; import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class'; @Component({ selector: 'app-root', styleUrls:['app.component.css'], templateUrl:'app.component.html', //template:`<h1>Hello world</h1>` }) export class AppComponent { title = 'ini tengah'; } export class DemoModalServiceStaticComponent { public modalRef: BsModalRef; constructor(private modalService: BsModalService) {} public openModal(template: TemplateRef<any>) { this.modalRef = this.modalService.show(template); } } 
 <!--the HTML file--> <!--call modal--> <li><a href="#" (click)="openModal(template)">BUTTON</a></li> <!--end--> <!--Modal--> <template #template> <div class="modal-header"> <h4 class="modal-title pull-left">Modal</h4> <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> This is a modal. </div> </template> <!--enf of modal--> 

I followed the website then just got that error. 我跟随网站,然后得到那个错误。 Can anyone help me fix this error? 谁能帮我解决此错误?

Plase let me know when more snippets is needed, Thank you in advance :) 请在需要更多片段时通知我,谢谢!

Try like this : 尝试这样:

write openModal method inside the Appcomponent 在Appcomponent内编写openModal方法

export class AppComponent {
  title = 'ini tengah';
  public modalRef: BsModalRef;
  constructor(private modalService: BsModalService) {}

  public openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM