The problem is where I override template with modalTemplate, then you get an infinite loop. But I've got a solution to that. I'll leave modalTemplate undefined and only override template when typeof(modalTemplate) === 'function'.