How to copy the generated html content within ng-repeat into a textarea?

Asked

Viewed 74 times

0

<div ng-repeat="(keyC, column) in columns.form" ng-model="columns.form"  >
  <div class="well">
     <p><strong>BLOCO {{ keyC }}</strong></p>
      <div ng-repeat="(keyP, p) in column.perguntas" ng-model="column.perguntas"  >
          <formulario  data="p" ></formulario>
      </div>
  </div>
</div>

How to copy the content that was generated in the DOM to a textarea? In fact only a few things should be generated within the textarea:

<div class="well">
   <p><strong>BLOCO 0</strong></p>
   <div class="alert alert-danger">88888</div>         
</div>
<div class="well">
   <p><strong>BLOCO 1</strong></p>
   <div class="alert alert-danger">123123123</div>         
</div>

Jsfiddle for better explanation: https://jsfiddle.net/na4t6k57/

I tried to do that, but I think it’s totally wrong:

<div ng-init="html = ''"></div>
<div ng-repeat="(keyC, column) in columns.form" ng-model="columns.form"  >
  {{ html += '<div class="well">' }}
    {{ html += '<p><strong>BLOCO' + keyC '</strong></p>' }} 
      <div ng-repeat="(keyP, p) in column.perguntas" ng-model="column.perguntas"  >
          {{ html += '<formulario  data="p" ></formulario>' }} 
      </div>
  {{ html += '</div>' }}
</div>

<textarea ng-model="html"></textarea>

1 answer

0

I was able to get the html through Jquery Lite that comes embedded in Angular. I put a id in ng-repeat initial and created a button with the function of placing html in the model follows link from my Jsfiddle - https://jsfiddle.net/unahk45a/

$scope.seta=function(){
    $scope.textarea = angular.element(document.querySelectorAll('#id')).html();
}

Explanation:

document.querySelectorAll() native Javascript selector

angular.element() will transform the object passed into a jquery lite object (if you have placed the Jquery dependency in your project it will be a Jquery object)

html() Jquery method that returns the html content of the Jquery object

  • There is even more 1 challenge that is to make a watch for this or run the arrow() function after ng-repeat has run.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.