Both words relate to teaching, but didactic teaches a lesson and pedantic just shows off the facts.

Didactic describes anything that tries to teach a lesson, sometimes a moral one. People don't always want a lesson. Didactic comes from the Greek didaktikos for "apt at teaching." Although being didactic is perfect for a teacher, it can be annoying when movies and books get into teacher mode. See below:

"Being Here is tough to absorb in one take, and it borders on being too didactic." (New York Times)

"It's not didactic or propagandistic in its approach, but it's honest. It makes you want to know more. It makes you want to get involved." (Washington Post)

Didactic also refers to a method of teaching that involves repetition:

"This is unnecessarily repeated, but fortunately such didactic intrusions are kept to a minimum." (Los Angeles Times)

The word pedantic is from the Italian pedante for "teacher." What a coincidence. Teachers aren't usually pedantic, but sticklers are. Pedantic music snobs list twenty bands from Iceland that you have to go listen to now. Pedantic grammar nerds say to never split an infinitive. Pedantic is not a compliment. Check out these examples:

"Tristram Shandy makes fun of nearly everything, but especially the pompous and pedantic." (Slate)

"I know that some readers may find my language-stickler columns pedantic, or, even worse, tedious." (The Guardian)

"Readers responded: They found this arbitrary, arrogant, pedantic and just plain wrong." (Washington Post)

It's cool if a teacher leads a didactic discussion on Hamlet, but it's not cool if the teacher's pet takes over with a pedantic rant about how it should always be referred to as The Tragedy of Hamlet, Prince of Denmark.