In angular, any manipulation of the DOM should really be handled in directive (see the documentation ). This concerns individual issues and enhances the ability to check other angular members, such as controllers and services .
The basic directive for sound reproduction might look something like this ( fiddle ):
app.directive('myAudio', function() { return { restrict: 'E', link: function(scope, element, attr) { var player = element.children('.player')[0]; element.children('.play').on('click', function() { player.play(); }); element.children('.pause').on('click', function() { player.pause(); }); } }; });
And the related HTML:
<my-audio> <audio> <source src="demo-audio.ogg" /> <source src="demo-audio.mp3" /> </audio> <button class="play">Play Music</button> <button class="pause">Pause Music</button> </my-audio>
source share