Just starting out with AngularJS and I've encountered an issue;
I'm populating part of my view with HTML from a variable in my controller:
<div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div>
Everything works as expected until I try to execute a script. The script is displayed, but it does not run. I suspect that the problem arises because the view is populated with my controller variable after the page has loaded, causing the script not to execute. The reason I am using a variable in my controller to store the script is because I need to retrieve the script from elsewhere and it changes frequently.
Is this a suitable approach for running my script?
Here's a snippet of my code:
View:
<div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div>
Controller:
.controller('browseCtrl', function($scope,$sce) {
$scope.video = '<div id="idxx1" style="width: 460px; height: 290px;" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"></div><script>addeere3ejs("idxx1", "172653", "24431581", "1_fq2w6oc2");</script>';
$scope.deliberatelyTrustDangerousSnippet = function() {
return $sce.trustAsHtml($scope.video);
};
})
If you're unclear about my question, feel free to ask for clarification.