solving an angular promise bug