modal close/dismiss methods wait for modalOpenDeferred to resolve

If you attempt to call dismiss() or close() on a modal instance before it has finished opening the function errors out. This is fixable by waiting until after the modalOpenedDeferred promise is fulfilled.