Due to CHF, circulation in your body is probably not very optimal, so you might get fluid build-up in certain places. Your ankles are probably as far as they can be from the heart so since your heart is not doing a good job of circulating, fluid just goes with the flow of gravity and deposits towards your ankles and legs, etc.
There are generally two types of CHF, left sided and right sided. What you're refering to is right sided CHF. The right vertricle pumps insufficiently causing a back-up of fluid as evidenced by swollen ankles. Left sided CHF is obviously when the left ventricle pumps insufficiently, but instead causes a back-up of fluid into the lungs leading to pulmonary edema. Treatment of these patients is usually a combination of fluid restriction and diuretics.
The above post does partly answer the question but you can get full body edema and pulmonary edema in CHF. CHF is not usually divided into right and left heart failure (right heart failure is relatively rare), but rather systolic and diastolic dysfunction. Anyways, the most important reason you have edema in CHF patients is because they are volume overloaded. the decreased pumping ability of the left ventricle delivers less blood to the kidneys than normal. In response the kidney secretes renin and activates the whole renin-aldosterone-angiotensin axis (look it up) which in turn decreases urine output and increases intravascular volume, which contributes to edema.