use factory from AngularJs instead of shared variable