Ionic bonding occurs as a result of an electron exchange. Most atomic nuclei do not posses a stable electronic configuration in their outer orbits; they either have an excess or deficiency. Those with an excess are likely to combine with those with a deficiency so that both atoms have a more stable configuration. However, in moving an electron from one to the other, both atoms become electrically charged, each forming an ion -- One becomes positive, and the other becomes negative. These opposing charges attract, and keep the atoms together, forming a compound.
Ionic bonding takes place when a metal transfers its electrons to a non-metal which has electronegativity. The non- metals which have a tendency to attract electrons towards itself attract electrons from the valece shell of the metal`s atoms. Due to the movement of electrons from one element to the other an ion is formed. Due to the opposite charges on the ions they attract and keeps the atoms together and forms a compound. I am totally with the answer given by enotechris