Wednesday, April 16, 2014

AngularJs with IPhone 3GS bug

I just killed annoying IPhone 3GS bug inside my angular app.

The symptom is when I hit "back" button, it doesn't want to go back.
I thought it was rendering bug in the old phone.
Luckily after spending couple hours debugging, it end up with problem inside "onDestroy" event of couple my directives.

It doesn't support element.remove(). which "remove" is undefined.
So I just need to use angular.element(element).remove() which fix the problem.

In summary, when your page doesn't render on back button or next button, make sure you check all onDestroy event on your particular page.

Tuesday, April 15, 2014

Recursively scroll

'use strict';
commonLib.factory('scrollHelper', ['$timeout', function ($timeout) {
//scroll to element recursively until found
function scrollToElement(scrollToId, maxRetry) {
var counter = 0;
function tryScroll() {
counter ++;
var el = document.getElementById(scrollToId);
if (el) {
el.scrollIntoView(true);
} else if (counter < maxRetry) {
//try scroll again
$timeout(tryScroll, counter * 10);
}
};
$timeout(tryScroll, 0);
};
return {
scrollToElement: scrollToElement
};
}]);