首页 > 解决方案 > 在选项中选择嵌套标签可防止调用方法

问题描述

在此处输入图像描述

当我单击带有选项的任何位置时,我正在尝试调用一个方法。

当您单击选项中的任何嵌套标签时,选择托盘将消失而不调用该方法。

如果您选择任何空白或任何未嵌套的文本,则将调用该方法。

<mdb-auto-completer 
    #completerBillTo
    #auto="mdbAutoCompleter"
    textNoResults="I have found no results :("
    [appendToBody]="true">
        <mdb-option 
            *ngFor="let billTo of resultsBillTo | async"
            [value]="billTo.name"
            (click)="updateAccountInfo( billTo, _accountService.accountFormGroup)">
                <small><strong> Id: {{ billTo.id }} </strong></small>
                {{ billTo.name }}
                <small>Value: {{ billTo.value }}</small>
        </mdb-option>
</mdb-auto-completer>

我尝试创建一个覆盖 div 并将其放置在所有元素的前面,但单击 div 不会在单击时调用任何内容。

标签: htmlangularbootstrap-material-design

解决方案


文档中,mdbAutoCompleter有一个select事件。选择选项后,事件将开火。

<mdb-auto-completer 
    #completerBillTo
    #auto="mdbAutoCompleter"
    textNoResults="I have found no results :("
    [appendToBody]="true"
    (select)="updateAccountInfo($event)"
>
    <mdb-option 
        *ngFor="let billTo of resultsBillTo | async"
        [value]="billTo"
    >
        <small><strong> Id: {{ billTo.id }} </strong></small>
        {{ billTo.name }}
        <small>Value: {{ billTo.value }}</small>
    </mdb-option>
</mdb-auto-completer>

如果只是在您选择标签时,您可以使用 css 修复此问题:

<mdb-option class="parent-class">
.parent-class {
  small, strong {
    pointer-events: none;
  }
}

这将删除smallandstrong元素的点击事件。


推荐阅读