@sometime sun,
I wouldn't quite say that loyalty is an emotion.
In a dog's case, it could be a built-in instinct of survival. The owner feeds and cares greatly for the dog.
When the dog is good it gets more attention, care and treats.
I have a dog myself, and I care greatly for him, and would like to think that he has some sort of emotion that cares for me, but it could all be a way in which the dog gets an easy life, so to speak.
Although if you bond enough with a dog, it's loyalty could become more potent, as you have integrated with it, not only as an owner, but as a friend.