0

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>

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

17 Comments

:-i tried to call in the way that i need to get my dynamic json inputs inside the form but its not working
module and basic components are missing in the codepen, please create a valid demo
:- can you please check now whats i made the changes you said .. codepen.io/anon/pen/ybOjqv
:- is there any way to put everything inside an (id=result) and call only that in html page ..i have the example in javascript but i couldn't do it in angular??? codepen.io/anon/pen/ybOjqv
add additional field to component array and put the result string to that field
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.