javascript - Is there a way to load data into script -
so in angular i'm trying do
$scope.data = "<script> alert('hi'); </script>";
but unfortunately doesn't work. tried add ng-bind-html without results.
{{data}}
also tried load data in script tag seems not work. there way avoid all? example
$scope.data = "bob";
-
<script> var name = {{data}}; </script>
you create directive load script dom dynamically.
markup
<load-script ng-if="data" data="data"></load-script>
directive
app.directive('loadscript', function($compile){ return { restrict: 'e', scope: { 'data': '=' }, link: function(scope, element, attrs){ element.append($compile(scope.data)(scope)) } } })
Comments
Post a Comment