admin管理员组

文章数量:1277377

As you can see in the code, there are two onClick() methods. Both appear on the UI. But when I click on the second onClick() method, it doesn't call the method but the first one calls. I am not able to understand why this is happening. Please help.

        <div class="col-sm-12 text-right mrg-top-15">
            <div class="action-btns text-right flex">
                <span class="icon-pending"></span>
                <vh-button [type]="'trash'" (onClick)="navigateToHRA()" class="mrg-lft-10" id="icd-delete"></vh-button>
            </div>
            <button (onClick)="navigateToHRA()" class="btn btn-primary">{{'LookUpButtonText'|translate}}</button>
        </div>

As you can see in the code, there are two onClick() methods. Both appear on the UI. But when I click on the second onClick() method, it doesn't call the method but the first one calls. I am not able to understand why this is happening. Please help.

        <div class="col-sm-12 text-right mrg-top-15">
            <div class="action-btns text-right flex">
                <span class="icon-pending"></span>
                <vh-button [type]="'trash'" (onClick)="navigateToHRA()" class="mrg-lft-10" id="icd-delete"></vh-button>
            </div>
            <button (onClick)="navigateToHRA()" class="btn btn-primary">{{'LookUpButtonText'|translate}}</button>
        </div>
Share Improve this question asked Jan 30, 2019 at 12:11 Prashant YadavPrashant Yadav 5512 gold badges10 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You need to use (click) when using Angular's click event.

<button (click)="navigateToHRA()" class="btn btn-primary">{{'LookUpButtonText'|translate}}</button>

The other (onClick) event is most probably the output event emitter of vh-button ponent/directive.

You have to use (click) on the button instead of (onClick) because that event does not exist on the native button.

本文标签: javascriptAngular Onclick() not working on second buttonStack Overflow