我有一個(gè)組件,它是一個(gè)用于打開(kāi)和關(guān)閉下拉元素的按鈕,以及當(dāng)存在ng-model值時(shí)用戶清除下拉列表中所選項(xiàng)目的選項(xiàng),如下所示:<button class="btn btn-default form-control" type="button" ng-click="ctrl.toggleDropdown($event)" ng-keydown="ctrl.onKeyboardPressed($event)" ng-mouseenter="icon=true" ng-mouseleave="icon=false"> <span ng-if="ctrl.ngModel !== null" > {{ctrl.ngModelValue ? ctrl.ngModelValue : ctrl.placeholder}} <i class="removeSelectionIcon" ng-class="{'fa fa-close' : icon}" ng-mousedown="ctrl.clearSelection($event)"></i> </span></button>為了簡(jiǎn)短起見(jiàn),當(dāng)用戶通過(guò)ng-mousedown點(diǎn)擊“fa-close”圖標(biāo)時(shí),我需要觸發(fā)下面的功能: function clearSelection($event) { console.log("hey there"); this.ngModel = null; this.ngModelValue = ""; $event.preventDefault(); $event.stopPropagation(); }一切都在Chrome中很棒,但我甚至無(wú)法在IE和Firefox中獲得console.log。當(dāng)我點(diǎn)擊圖標(biāo)時(shí),下拉菜單只是打開(kāi)和關(guān)閉,就好像我點(diǎn)擊按鈕本身一樣。我注意到,如果我快速雙擊圖標(biāo)我可以清除所選行,但有人知道我需要做什么才能在點(diǎn)擊“fa fa-close”圖標(biāo)時(shí)觸發(fā)mousedown事件?非常感謝幫助!
在IE和Firefox中使用ng-mousedown嵌套內(nèi)部按鈕調(diào)用Angular控制器功能
慕勒3428872
2019-04-17 18:19:37