List html in a textarea

3

I know that to list in html code is:

<ol>
  <li>Este será el 1. </li>
  <li> Este será el 2. Y así sucesivamente. </li>
</ol>

The fact is that I need it in a textarea or in some way. I need to make the user answer a question and list their answers, but the user does not put "1-" but it automatically comes out.

NOTE:

  • The response will be sent in a POST form to be saved later in the BBDD
  • If the answer is already answered, it is loaded like this, you can edit it again

    <div ng-repeat="resp in respuestas">
        {{resp}}
    </div>
    
asked by sirdaiz 13.07.2017 в 09:35
source

2 answers

5

It's enough that you create a div that is editable and put the list structure inside. Each time you enter, the next number comes out automatically.

I use a div because a textarea does not interpret the from the interior.

div.editable {
  width: 300px;
  height: 100px;
  border: 1px solid #ccc;
  padding: 5px;
  overflow: auto;
}
  <div contenteditable="true" class="editable" id="divEditable">

    <ol>
      <li>Este será el 1. </li>
      <li> Este será el 2. Y así sucesivamente. </li>
    </ol>

  </div>
    
answered by 13.07.2017 в 09:58
1

Well to achieve your goal you can use ng-repeat on an array or an array-json and you're showing with {{x.id}} for each iteration. note that .id is an attribute of the array-json

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    {id:1,name:"maria"},
    {id:2,name:"jose"},
    {id:3,name:"lucy"},
    {id:4,name:"gaby"},
  ]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="myCtrl">
    <div ng-repeat="x in records">{{x.id}}.- {{x.name}}</div>
  </div>
</div>
    
answered by 20.07.2017 в 03:25