It takes time, but I used to yell and drag the leash, and now it looks and feels a lot better when I just click and treat, lol.
Now, at first, when you start this, you have to make sure that YOU see the other dog coming before the dog does. That way you can try and grab his attention first (at first it's more like a distraction) then after lots of practice it is a compliance. Now here and there the dog may see another dog at the same time you do and it may be too late for distraction. Don't worry about it, just keep trying.