Why doesn't the double-slit experiment violate the uncertainty principle? In the double-slit experiment, when an electron reaches the detector after passing through the holes, it has a certain momentum which we can measure with arbitrary accuracy.
From this data, we can calculate what momentum the electron had when it was passing through the hole.
So we can know the electron's position (as it was inside the hole) with arbitrary accuracy and also simultaneously know its momentum.
Doesn't this violate the uncertainty principle? Where have I gone wrong?
 A: The narrower the slits ($dx$), the broader the expected (measured and/or calculated) distribution of momentum ($dp$) of the photons passing said slits, so the product ($dx.dp$) cannot get arbitrarily small, therefore the Heisenberg principle ($dx dp \geq \hslash$) is respected in the double slit experiment.
A: 
Where have I gone wrong?

Here, the noted with italics.

when an electron reaches the detector after passing through the holes, it has a certain momentum which we can measure with arbitrary accuracy.

Any measurement means new quantum mechanical interactions, i.e. new wavefunctions and boundary conditions on them. In any case momentum is measured also within the Heisenberg uncertainty bounds.
Also here:

So we can know the electron's position (as it was inside the hole)

The width of the hole is the accuracy we can experimentally have, there is no way it can be better.
A: 
In the double-slit experiment, when an electron reaches the detector after passing through the holes, it has a certain momentum which we can measure with arbitrary accuracy.

The weird thing about quantum mechanics is that the electron actually does not have a definite momentum. It would only have a definite momentum if it were in an eigenstate of the momentum operator (which is not physical, due to not being normalisable). When you measure the momentum, the electron transitions to (an approximation of) an eigenstate of the momentum operator, corresponding to the measured (eigen)value; i.e. measurement changes the state of the electron.

So we can know the electron's position (as it was inside the hole) with arbitrary accuracy and also simultaneously know its momentum.

Note the tense here. The Heisenberg uncertainty principle places a limit on how precisely the position and momentum can be defined (not just known) for a single state.
However, your measurements of the position and momentum were at different times, and since each measurement changes the states of the electron, the measured values describe different states. Thus, the potential arbitrary precision in the measurements does not violate the Heisenberg uncertainty principle.
A: 
From this data, we can calculate what momentum the electron had when it was passing through the hole.

We can't do this. It is true that in principle, we can measure all three components of momentum $p_x,p_y,p_z$ with arbitrary precision at single time, but in general, we do not know how to extrapolate this to past to find "particle's components of momentum" at some known previous time or assign momentum to some region of space ("hole in the wall").
We can do naive extrapolation by assuming that momentum did not change at all, so the particle always had the momentum we measured. But this is unphysical, because we know the particle had to interact with the wall, and with other bodies before that. So this naive extrapolation is good only for limited span of time/region of space where interaction is believed to be negligible.

So we can know the electron's position (as it was inside the hole) with arbitrary accuracy and also simultaneously know its momentum.

No, because we can't extrapolate the momentum measurement back to time when the particle was "inside the hole", and also we do not know exactly where the particle is when we find its momentum, so we can't just draw a line from "position of particle when its momentum was measured"; there is no such single point.
A: I don't believe the accepted answer is correct. Here is the resolution: The uncertainty principle
$$\sigma_x \sigma_p \geq \hbar/2$$
is derived for the state at a particular time $\psi(x,t)$. However in your case, there are two different states involved: the position measurement$^*$ is done on the wavefunction before interaction with the screen, and the momentum measurement is done after the interaction with the screen and wavefunction.
So your question compares $\sigma_x$ for $\psi_{before}$ against $\sigma_p$ for $\psi_{after}$, and the uncertainty relation does not apply for these two unrelated quantities. The interaction with the screen causes $\psi_{before} \neq \psi_{after}$.
*Note: Since it is not done at a fixed and chosen time, the double slit screen is not a "textbook" position measurement either, so the usual derivation for the uncertainty relation does not apply. This is a separate discussion.
A: In order to measure through which hole the electron goes you need a device with at least two, orthogonal, states, say L and R. The setup must be such that L and R are coupled to the left and right part of the wave function, respectively, so that $$\psi = |L {\cal L} \rangle + |R {\cal R} \rangle \,.$$ This means that the two parts of the wave function are orthogonal so that no interference occurs
S, yes, you can in principle measure through which slit the particle went but this eliminates the interference pattern.
