Hello Angular community,
I'm a beginner developer and i've been struggling lately trying to embed
the Twitch video player in my AngularJS front end.
>From my research, it seems like creating a directive and using
angular.element is the way to go but now i’ve been stuck at that point for
a while.
Here’s my directive function code:
function testDirective() {
return {
restrict: 'EA',
template: '<script
src="https://embed.twitch.tv/embed/v1.js"></script> <div id="twitchemb"></div>',
link: function($scope, iElm, iAttrs) {
var script = '<script type="text/javascript">'
'var options = {'
'width: 854,'
'height: 480,'
'};'
'var player = new Twitch.Player("twitchemb", options);'
'</script>';
var scriptElem = document.createElement(script);
scriptElem.attr("src",
"https://player.twitch.tv/?autoplay=false&video=v165913358&t=15707s"); // set
var appropriately
element.append(scriptElem);
}
};
};
When I remove the link attribute entirely and use a dummy template, say
"<div>yo</div>, then I get the "yo" displayed in my html page.
But when using the code above, I get a "String contains invalid character
error". I think the issue is coming from the script variable used by
document.createElement().
Am I way off the mark?! Is it just a little syntax mistake?
Any kind of light shed on the matter will be greatly appreciated!
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" 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.