The magnetometer uses microchips (no moving parts) to sense the magnetic field in three dimensions. It turns the information into a digital stream of data that is sent up to the EFIS for display, and the EFIS combines this magnetic information with pitch and roll information to make a compass heading that works at all aircraft angles.
If you are really looking for the deep theory on how it does the conversion from magnetic field to an electronic signal, google "solid state magnetic sensor"