When the circuit is closed, the coil acts as an electromagnet and interacts with the compass which is near it. The phenomenon is explained by the creation of a magnetic field inside the coil. If you want to calculate the value of this field inside and at the poles of the coil, click here.