Explain the formation of an ionic compound between metal and a non-metal by transfer of electrons with Mg as the metal and Cl as a non-metal to illustrate your answer.