I am not sure how to avoid this. My yorkie is exactly the same. I just don't worry about it and explain to the other dog owners that he is just excited. Loki isn't doing anything bad- and neither is your dog- they are happy and full of energy- nothing wrong with that. Maybe if your yorkie is around more dogs more often he will get used to it and eventually calm down a little. But in my opinion- after years of having different kinds of dogs of all ages- they are all always excited to see other dogs and have that few minutes at the beginning where they seem out of control- but they are really just super excited.
Hope that helps