Reputation: 967
I need to print this array in a form. but it should generate automatically without writing in html file. I tried but I'm not getting the result.
This is to print the values and generate the result (need to write the code in .js file).
result+='<form action="http://www.example123.com" method="post" onsubmit="target_popup(this)">';
for(component in components){
result+= mylogic(component,components);
}
"<div> <button >Submit</button> </div></form>";
$scope.target_popup=function (form) {
window.open('', 'formpopup', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,width=400,height=400,resizeable,scrollbars');
}
})
<html>
<div ng-bind-html="mylogic(result) | unsafe"></div>
</html>
Upvotes: 0
Views: 176
Reputation: 41387
you can use $sce.trustAsHtml(html)
render html from js
create a filter like this
.filter('trust',function($sce){
return function(html){
return $sce.trustAsHtml(html)
}
})
call it in the html
<div ng-bind-html="result | trust">
</div>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.result ='<form action="http://www.example123.com" method="post" onsubmit="target_popup(this)"><div> <button >Submit</button> </div></form>';
})
.filter('trust',function($sce){
return function(html){
return $sce.trustAsHtml(html)
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-bind-html="result | trust">
</div>
</div>
Upvotes: 1