When a metal and a non-metal react together the metal atom loses electrons to form a positive ion and the non-metal gains these electrons to form a negatively charged ion.
Ions are held together by strong forces so they have high melting points and boiling points
The attraction between oppositely charged ions is called an electrostatic force
When the compounds are solid, the ions are held in place so they can't conduct electricity.
When ionic compounds melt the ions are free to move and they'll carry electric charge.
Some ionic compounds can dissolve in water. The ions separate and are free to move, so they'll carry an electric charge.