Calling a function when ng-repeat has finished

var module = angular.module(‘testApp’, []) .directive(‘onFinishRender’, function ($timeout) { return { restrict: ‘A’, link: function (scope, element, attr) { if (scope.$last === true) { $timeout(function () { scope.$emit(attr.onFinishRender); }); } } } }); Notice that I didn’t use .ready() but rather wrapped it in a $timeout. $timeout makes sure it’s executed when the ng-repeated elements … Read more

JavaScript: remove event listener

You need to use named functions. Also, the click variable needs to be outside the handler to increment. var click_count = 0; function myClick(event) { click_count++; if(click_count == 50) { // to remove canvas.removeEventListener(‘click’, myClick); } } // to add canvas.addEventListener(‘click’, myClick); EDIT: You could close around the click_counter variable like this: var myClick = … Read more

Global keyboard capture in C# application

Stephen Toub wrote a great article on implementing global keyboard hooks in C#: using System; using System.Diagnostics; using System.Windows.Forms; using System.Runtime.InteropServices; class InterceptKeys { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private static LowLevelKeyboardProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; public static void Main() { _hookID = … Read more

How to remove all event handlers from an event

I found a solution on the MSDN forums. The sample code below will remove all Click events from button1. public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Click += button1_Click; button1.Click += button1_Click2; button2.Click += button2_Click; } private void button1_Click(object sender, EventArgs e) => MessageBox.Show(“Hello”); private void button1_Click2(object sender, EventArgs e) => … Read more

What’s the difference between event.stopPropagation and event.preventDefault?

stopPropagation prevents further propagation of the current event in the capturing and bubbling phases. preventDefault prevents the default action the browser makes on that event. Examples preventDefault $(“#but”).click(function (event) { event.preventDefault() }) $(“#foo”).click(function () { alert(“parent click event fired!”) }) <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <div id=”foo”> <button id=”but”>button</button> </div> stopPropagation $(“#but”).click(function (event) { event.stopPropagation() }) $(“#foo”).click(function () … Read more