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))     }   } }) 

working plunkr


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -