The positive pole of a DC battery is made of steel (iron). Electrons have to move for an electromagnetic field to be present. You can swipe a screwdriver tip across a magnet just twice and and it will pick up screws. A digital compass only needs a very tiny magnetic field, so literally any variance in the field will affect it's ability to determine magnetic north.
One of our "projects" in college (University of Houston physics dept.) was to observe and explain how current flowing thru a circuit affected a compass needle. Even when the circuit was open, the battery still affected the compass needle. No current was flowing, so no electrons were moving. There shouldn't have been any affect if there was no iron in the battery and the battery was not connected in a circuit. The reason was the current flowing thru the circuit when the battery was previously connected magnetized the positive anode just a tiny bit. The electrons in the anode steel of the battery all magnetically aligned when the battery was included in closed circuit. But then the question was, why does a brand-new battery just taken out of the package still affect the compass needle? According to laws of physics, if the battery was never connected in a circuit, and thus no electrons ever moved to align the electrons in the ferrocarbon material, the battery shouldn't affect the compass needle. The answer was the automated machinery the battery was manufactured on has electric motors and electric circuits, and the positive anode of the battery was magnetized during the manufacturing process.
If you put your magnetic compass beside the copper or aluminum wires in the walls in your house, and those wires are in a closed circuit with electrons flowing thru it, it will affect your compass even though copper and aluminum aren't' ferrous metals.
At the atomic level, it isn't the IRON itself that creates magnetism. It's the electrons flowing thru the iron that make the iron magnetic. The earth itself is a huge circuit, so any iron from earth is already magnetized, even in it's natural ore form. If you can get access to CHAMP images (the German space agencies satellite that constantly measures the earths magnetic field), you can actually see detailed evidence of the electron flow around the earth and how the North pole moves. I forget now, it's been 20 years, but I think it was like 1/4 inch per year or something like that.
Back in 1990 when I was in the military, we had satellites so sensitive to earths magnetic field that they could find Russian subs under the ocean by measuring the earths magnetic field in a given area and comparing it to what that magnetic field was in that same area the week (or day) before. A variance in the magnetic field meant something huge and iron was there. If it wasn't there yesterday, it shouldn't be there today.
The Russians got smart and started building their subs with titanium in the late 70's to circumvent our magnetic satellites but couldn't get the alloy right and lost a lot of subs when cracks formed in the hulls because the titanium was too brittle. Due to the shortage of titanium in the 70's they also only used titanium for the outer pressure hull. The inner hull was still iron. So their sub was still "findable" by satellites. It got more difficult in the '90's when they perfected the alloy and began using titanium for their Alfa-class fast attack sub hulls. This time they had an abundance of titanium so they could make both the light hull and the pressure hull from titanium. The electromagnetic field variance was much less and you got a lot of false positives. Once they went to titanium hulls, the only EMF interference you detected was from the electronics (moving electrons in a closed circuit) and the small bit of collateral iron used in the sub.
EM field anomalies are one of the ways our boomers stay under water for months at a time. GPS doesn't work underwater. The radio signal only penetrates about 4 inches deep. A sub would have to surface or raise an antenna to pick up GPS radio signals. Both of those actions compromise it's location. But by mapping all the magnetic field anomalies created by shipwrecks and known iron deposits on the ocean floor, the subs computer can triangulate it's position and know pretty close where it is on the globe. Then the computer pulls up a ocean floor sonar map of that area and compares that to what it sees on it's active sonar and it knows it's exact position.