If a dog goes after you on a bike it is normally one of three things. Trying to say hello, in which case just stop and be friendly and it will either stop or may need to be told to sit. It wants to chase you and may be getting over excited, in this case firmly tell it off and get it to sit or not move.
The final one is trouble when a dog is growling and bearing its teeth, this means it is on the verge of attacking / biting you. Being firm, calm and confident can help but what happens is often more down to luck.
For non dog owners it is almost impossible to tell these appart and even harder to firmly control a dog by voice and body language. Which is why the owner of the dog should train it well, socialise it well and not put the dog into situations it finds stressful. If unsure keep it on a short lead out of harms way.
To give you an example while cycling on the canal recently a dog started barking and lunging at me. I could tell it was scared and not angry, so i stopped and said hello, let it sniff my hand, talked to the owner and carried on. Cycling past a drive way two jack Russell terriers came charging out onto the road, barking and snapping so i told them in no uncertain terms where to go and they ran off. A non dog owner would have no chance.