Wednesday, September 6, 2017

feel out the gift from the wrapper

Let's say a third party control revamps an html tag, turning a select list into a bunch of span tags with some li items nested further inside. Well, that means that you can't really put Angular 4 events on the select tag and expect them to do anything as they are gonna get wiped away in the replacing of one thing with another, right? So what can you do to jam in your own events? You can wrap the disappearing thing in another tag and then put an event on it like so:

(click)="onDropDownClick($event)"

 
 

Then you can make sense of what piece of the wacky apparatus was clicked on because the classes for the bit that was clicked on will be exposed and will differ across different elements.

onDropDownClick(dd: any){
   console.log('made it this far');
   if (dd && dd.toElement && dd.toElement.className == "select2-results__option"){
      console.log(dd.toElement.textContent);
   }
}

No comments:

Post a Comment