move openPopup call out of angular apply function