Hi Andrei,
Why don't use a small component to enable play-on-click?
Something like:
(function() {
'use strict';
angular
.module('Module')
.component('myPlayer', {
template:`
<audio src="{{'media/question_' + ($ctrl.index+1) +
'.mp3'}}" type="audio/mpeg"></audio>
<div class="btn" ng-click='$ctrl.playMe()' >Play</div>
`,
controller: ControllerController,
bindings: {
index: '='
},
});
ControllerController.inject = ['$element'];
function ControllerController($element) {
var ctrl = this;
////////////////
ctrl.onInit = function() {
crtl.audioEl = $element[0].getElementsByTagName('audio') ; //get
the audo element contained in this component
};
crtl.playMe = function () {
ctrl.audioEl.play();
}
}
})();
and use it like this in your template:
<my-player index="$index></my-player>
It would unclutter a lot of your code, and encapsulate the whole handling
of the audio stuff inside a single component.
Regards
Sander
PS, I just typed this up as an example and didn't run/try it at all!, it
might need some filling to get it running for real! ;)
--
You received this message because you are subscribed to the Google Groups
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.