I had a friend whose dog did the same thing. Her trainer said the moment that Sandy began to bark or act with aggression while on the leash to turn her in the opposite direction until she stopped, even stopped turning to look. Then to turn and go towards the other dog again and repeat this as many times as necessary giving a stern, "Bad dog." when the dog barks and an immediate praise when it stops. The barker soon learns that it does not get to walk where it wants if it barks.
It took a while, but Sandy no longer ever barks at other dogs while on the leash.