data generate function converted into service and working using angular  promises