【问题标题】:Angular 9 materialize css modal not recognizing methodsAngular 9具体化css模式无法识别方法
【发布时间】:2021-09-02 19:00:33
【问题描述】:

我有一个 Angular 9 应用程序,我正在使用 materialize-css 1.0 库将模态添加到我的应用程序中,我可以毫无问题地实例化/打开模态,但我的模态中有一个确认和关闭按钮但它似乎无法识别 .ts 文件中的任何方法。

file.component.ts

@ViewChild('modal', { static: false }) modalElement: ElementRef;
myModal = null;

...
ngAfterViewInit() {
    this.myModal = new M.Modal(this.modalElement.nativeElement, {});
}

openModal() {
   this.myModal.open();
}

closeModal() {
   this.myModal.close();
}

confirmModal() {
   ...some logic
}
file.component.html

<div id="modal" class="modal" #myModal>
   ...
   <button onclick="confirmModal()">confirm</button>
</div>
 

当我的模态打开并单击模态内的确认按钮时,出现参考错误:

confirmModal 没有在 HTMLButtonElement.onclick 中定义

【问题讨论】:

    标签: angular typescript materialize


    【解决方案1】:

    我使用了错误的符号onclick,它是(click)

    【讨论】:

      猜你喜欢
      • 2020-09-06
      • 2020-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2014-06-28
      相关资源
      最近更新 更多