added guard against in-progress $apply
Added Array.indexOf shim