Hi!
I just got my first ever dog a month ago. He's a black lab/blue heeler mix-- very intelligent and energetic, as one would suspect! We adopted him at fourteen months and he was already pretty well-trained, although he had to learn his manners around the house.
I've been doing lots of research to try to make our family as harmonious as possible. He's definitely submissive to me (he's learned how to walk beside me when we're out and about and I go through doors/up the stairs in front of him). He knows he has to earn his dinner by sitting calmly first. He's learning not to jump when we come home (but it's a work in progress, lol). We're also working on bringing his "alert" barks down to acceptable levels so he'll stop when acknowledged. He also knows he's submissive to my husband and our cats, all of whom have their claws and have made sure he knows they're the bosses.

So, basically, he's an angel when we're at home, and when we're out walking... as long as we don't encounter other dogs or people.
Sometimes, Edgar can walk calmly past another calm dog. Sometimes, Edgar can walk calmly past playing children. Sometimes, we can pass by a pair of adults on a stroll and have nothing happen.
And then sometimes, he lunges at these people/situations. It varies from just pulling really hard on the collar (which I'm never braced for because he'll have been walking quietly at my side for a half hour) to lunging, growling, snapping, and barking, and being very intimidating. Fortunately, he's not a huge dog (only 45 lbs) and I've managed to restrain him so far. It's also a problem when he meets other dogs: sometimes he'll be friendly and sniff them quietly, and then sometimes he'll initiate a fight. (The latter is extra-bizarre because he's been attacked before and thought it was just THE FUNNEST THING EVER and tried to play with his attacker with no hint of aggression.)
I can never tell which he's going to do. I try to exude calm and confidence and keep his attention so he remembers that I'm the alpha, but he can just go so bonkers sometimes. It's gotten to the point where I'll divert our walk if I see people coming up on us, which sometimes involves going a mile out of our way to have an uninterrupted walk. I hate having to tell children they can't pet the "pretty puppy," just in case he gets aggressive with them.
This is all scary to me because my husband and I plan on starting to have children in the next year or two, and I don't want to have a dog whose aggression I can't predict in the same house as an infant.
Does anybody have any suggestions? I love my dog. He's such a sweetheart at home. But these occasional attacks and acts of aggression are terrifying.
Thanks in advance!