Angular 2 Hover event

前端 未结 9 1168
深忆病人
深忆病人 2020-12-02 06:20

In the new Angular2 framework, does anyone know the proper way to do a hover like an event?

In Angular1 there was ng-Mouseov

9条回答
  •  旧时难觅i
    2020-12-02 06:55

    For handling the event on overing, you can try something like this (it works for me):

    In the Html template:

    Alerts

    In the angular component:

        onHovering(eventObject) {
        console.log("AlertsBtnComponent.onHovering:");
        var regExp = new RegExp(".svg" + "$");
    
        var srcObj = eventObject.target.offsetParent.children["0"];
        if (srcObj.tagName == "IMG") {
            srcObj.setAttribute("src", srcObj.getAttribute("src").replace(regExp, "_h.svg"));       
        }
    
       }
       onUnovering(eventObject) {
        console.log("AlertsBtnComponent.onUnovering:");
        var regExp = new RegExp("_h.svg" + "$");
    
        var srcObj = eventObject.target.offsetParent.children["0"];
        if (srcObj.tagName == "IMG") {
            srcObj.setAttribute("src", srcObj.getAttribute("src").replace(regExp, ".svg"));
        }
    }
    

提交回复
热议问题