The apparent contradiction is easily enough resolved -- anger is a broad term meaning "the desire for revenge," and "revenge may be desired both well and ill." But this, of course, just swaps "anger" for "revenge," and we're left with the question of whether revenge really can be desired both well and ill.
As St. Thomas points out in an objection:
Now it would seem unlawful to desire vengeance, since this should be left to God, according to Dt. 32:35, "Revenge is Mine." Therefore it would seem that to be angry is always an evil.
As often happens, St. Thomas grants much of the objection:
It is unlawful to desire vengeance considered as evil to the man who is to be punished, but it is praiseworthy to desire vengeance as a corrective of vice and for the good of justice... and when revenge is taken in accordance with the order of judgment, it is God's work, since he who has power to punish "is God's minister," as stated in Rm. 13:4.
There's a lot going on in this reply, and it needs to be read in the context of the whole article, so that for example you see in the main body of the article he has already said that all anger is evil when "one is angry, more or less than right reason demands." But here let me point out just a few things.
First, St. Thomas says "it is praiseworthy to desire vengeance as a corrective of vice and for the good of justice." It is to each person's conscience that he must look to decide how often his anger is directed toward correction of vice and the good of justice. Even when anger is directed toward these goods, one must determine whether the actions taken under its spur are at all likely to effect correction and justice. The passion of anger is often inflamed for reasons not in accordance with the order of judgment, and often not in circumstances in which the order of judgment can be served by the one who is angry.
Which leads to the second point, that my desire for vengeance is not necessarily a desire that I, personally, do the punishing. I can be justly angered by something I read in a newspaper without entertaining the thought of traveling to wherever the injustice occurred and knocking together the heads of the guilty.
What I don't see that I can do, though, is nurse the desire for vengeance without ever acting on it in some way that might contribute to the restoration of justice.
Finally, I think there's a real risk with humans that what begins as a corrective of vice becomes an unreasoned, habitual response. It is never in accordance with the order of justice to treat another person as an object; with anger, the danger is of treating another person as something that, when it acts in some way, we correct by kicking it, so to speak. Vengeance can never be indiscriminate; if it becomes habitual, it becomes vicious.