Sander, thanks so much!
I did it and your bit of code really helped a lot. I'm really a noob: I had
no idea about DOM manipulation with javascript. Deciphering your code
helped me make sure I was learning the right things to write the rest of it.
Here's the final working code to get Twitch' embed inline script loaded via
an AngularJS directive:
function testDirective() {
return {
restrict: 'EA',
replace: false,
template: '<div id="yoyoyo"></div>',
link: function(scope, element, attrs) {
function scriptLoad(src) {
return new Promise(function (resolve, reject) {
const s = document.createElement('script');
document.head.appendChild(s);
s.src = src;
s.addEventListener('load', resolve);
});
}
scriptLoad('https://embed.twitch.tv/embed/v1.js').then(function(response) {
console.log(response);
var testE = angular.element('<script/>')
.attr('type', 'text/javascript');
var scriptText =
'var options = {' +
'video: "v165913358"' +
'};' +
'var player = new Twitch.Embed("yoyoyo", options);';
testE[0].text = scriptText;
element.append(testE);
})
}
}
}
Somehow using "Twitch.Player" towards the end threw a "not a constructor"
error but I saw someone using "Twitch.Embed" while wandering on Twitch
forums and it worked like that for me.
Cheers
On Wednesday, 15 August 2018 17:32:01 UTC+2, Sander Elias wrote:
>
>
> Hi Nicolas,
>
> Something like this(untested):
>
> function scriptLoad(src) {
> return new Promise(resolve => {
> const s = document.createElement('script');
> s.addEventListener('load', resolve);
> document.head.appendChild(s);
> s.src = src;
> });
> }
>
> scriptLoad('someScript').then(() => {
> // do the things you want to do once the script is loaded.
> });
>
>
> Probably will do?
>
> Regards
> Sander
>
--
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.